1

mask validation textfield, can anyone help me with this? I am creating a registration form, and is difficult to make validations.

I need

  • PhoneNumber
  • DateOfBirth
  • Credit Card fields

1 Answers1

1

I have been doing this manually. In the cosmic mind documentation they have demos using storyboards. I have followed these and placed IBActions in my ViewController swift code. Essentially you just place a label and assign it the class of TextField from the Material module. In swift, I have this for example for a username field:

@IBAction func userNameModified(sender: AnyObject) {
    if(sender.text!.characters.count < 6) {
    userNameField.detail = "must be at least 6 characters"
    }else if (sender.text!.characters.count > 20){
        userNameField.detail = "must be less then 20 characters"
    } else {
        userNameField.detail = ""
    }

}

I was looking for a validator library as I want to also detect if it contains symbols, and came across this: SwiftValidators Library

They seem to have most of the fields you want to validate, credit card, phone number, dates, as well as many others. I am hoping to test if this works later today/tomorrow.

kinghenry14
  • 1,187
  • 1
  • 11
  • 34