I am trying to check text with a regular expression in iOS, and below is my code. My regular expression is accepting one word or number which it should be minimum 8 and maximum 16 with numbers or alphabetic.
if (![self validate:txtPass.text regex:@"^[a-zA-Z0-9]+$"]){
NSLOG(@"Check value");
}
What should I change in my regular expression?
^[a-zA-Z0-9]{8,16}$
You can specify the minimum/maximum gathered using {X,Y} as the boundaries.
Other examples:^[a-zA-Z0-9]{8,}$
#8 or more characters^[a-zA-Z0-9]{,16}$
#Less than or equal to 16 characters^[a-zA-Z0-9]{8}$
#Exactly 8 characters
Regex cheatsheet
You just need to put bounds on, not the + (one or more) operator.
^[a-zA-Z0-9]{8,16}$
^[A-Za-z0-9]{8,16}$
Specify a min/max length for a part of an expression using {x,y}
, where x
is the minimum and y
is the maximum.
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