I'm using the following regex to validate the name:
> ^[a-zA-Z]{1}[a-zA-Z.' ]{1,20}$
The single quote is mentioned in the second range. However, when I validate a string against this regex, the single quote (') invalidates the match. Here's my code:
let nameRegEx = "^[a-zA-Z]{1}[a-zA-Z.' ]{1,21}$"
let nameTest = NSPredicate(format:"SELF MATCHES %@", nameRegEx)
let isNameValid = nameTest.evaluate(with: name)
I've tried \'
but no use.
Turns out textField.text
returns ’
and not '
. Changing the character resolved the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With