Protocol
DSInputMask
public protocol DSInputMask
A masking object that controls what can be legally typed into a DSTextField and handles type formatting while that typing takes place. They do not validate but often "partner" up with validation rules.
Built-in input masks exist for common inputs such as DSEmailAddressInputMask, but you can create your own by implementing this protocol.
Input masks are added to DSTextField as follows:
let textField = DSTextField()
textField.inputMask = DSEmailAddressInputMask()
Relationships
Types Conforming to DSInputMask
DSCreditCardInputMask
An input mask, when assigned to a DSTextField, will enforce use of a number pad for text entry and format credit card numbers if it recognizes the brand of the card being entered. (e.g. Visa, Mastercard, etc.)
DSCurrencyInputMask
An input mask, when assigned to a DSTextField, will enforce use of a decimal pad for text entry and only allows digits and a decimal point (no more than one) to be entered.
DSEmailAddressInputMask
An input mask, when assigned to a DSTextField, will enforce use of an email keyboard for text entry and prevents invalid typing of email addresses where possible.
DSMaxTextLengthInputMask
An input mask, when assigned to a DSTextField, will enforce use of a maximum number of characters allowed.
DSNumberInputMask
An input mask, when assigned to a DSTextField, will enforce use of a number pad for numeric entry where only digits are allowed.
DSPhoneNumberInputMask
An input mask, when assigned to a DSTextField, will enforce use of a number pad for text entry and allows only digits to be entered and formatted. Only 10-digit phone numbers are allowed.
Requirements
keyboardType
var keyboardType: UIKeyboardType?
The software keyboard type the attached field should use
rawText(from:)
func rawText(from text: String) -> String
Returns the raw text in the field, minus all formatting symbols
shouldAllow(replacementString:resultingString:)
func shouldAllow(replacementString string: String, resultingString: String) -> Bool
Returns true if the text being entered, the replacementString, and the resulting string are allowable. If there are invalid characters in either, false should be returned.
Parameters
Name | Type | Description |
---|---|---|
replacementString | String |
The text that was added to the text |
resultingString | String |
The completed text as it would appear after replacement |
Returns
True if the text should be allowed
applyFormattingMask(to:)
func applyFormattingMask(to originalText: String) -> String
Returns a formatted version of originalText.
Parameters
Name | Type | Description |
---|---|---|
to | String |
Raw, original text that should be formatted. (e.g. 3035551234) |
Returns
Formatted text. (e.g. 303-555-1234)