Mask for Uitextfield

Asked

Viewed 6,761 times

2

How to apply mask on a UITextField? I found some ways to apply a mask on a UITextField, but it did not seem to me something very correct to do. It can be an example of telephone mask, very simple. It can be in Swift or Objective-C.

Note: a way that does not look like a "gambiarra"

  • I didn’t understand your question, what do you mean by a "mask"? a regular expression to validate the text?

  • It would set a default for the Uitextfield String. Example: Phone field: (##)####-####

  • Or also example of value field: $##,##

  • 1

    For the phone case, I answered another question here. For monetary value, you can try something from here.

2 answers

4


You can use Vmasktextfield where you just need to indicate a mask to take the format.

For example:

self.maskTextField.mask = @"(##) ####-####";

Other examples:

Exemplo

1

You have to implement Textfield’s "shouldChangeCharactersInRange" method.

Within the method applies the validation of the text you want whenever there is a change in the text. A great solution I came to use, allows you to easily apply a reg and text to get that same formatted text.

Analyze the code and apply your needs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.