EnterpriseDS Documentation

Protocol DSInput​Mask

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()
DSInputMask DSInputMask DSCreditCardInputMask DSCreditCardInputMask DSCreditCardInputMask->DSInputMask DSCurrencyInputMask DSCurrencyInputMask DSCurrencyInputMask->DSInputMask DSEmailAddressInputMask DSEmailAddressInputMask DSEmailAddressInputMask->DSInputMask DSNumberInputMask DSNumberInputMask DSNumberInputMask->DSInputMask DSMaxTextLengthInputMask DSMaxTextLengthInputMask DSMaxTextLengthInputMask->DSInputMask DSPhoneNumberInputMask DSPhoneNumberInputMask DSPhoneNumberInputMask->DSInputMask

Types Conforming to DSInput​Mask

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

keyboard​Type

var keyboardType: UIKeyboardType?  

The software keyboard type the attached field should use

raw​Text(from:​)

func rawText(from text: String) -> String

Returns the raw text in the field, minus all formatting symbols

should​Allow(replacement​String:​resulting​String:​)

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

replacement​String String

The text that was added to the text

resulting​String String

The completed text as it would appear after replacement

Returns

True if the text should be allowed

apply​Formatting​Mask(to:​)

func applyFormattingMask(to originalText: String) -> String

Returns a formatted version of originalText.

Parameters

to String

Raw, original text that should be formatted. (e.g. 3035551234)

Returns

Formatted text. (e.g. 303-555-1234)