ios - Regular expression for password validation - Objective C -
i need regular expression can validate following cases,
- be 8 20 characters
- use @ least 1 upper case letter, 1 lower case letter, , 1 number
- not repeat same number or letter more 3 times in row
- not contain spaces, , may use these characters @ # * ( ) + = { } / ? ~ ; , . - _
the closest solution can find
^(?=.*[a-z])(?=.*[a-z])(?=.*\d)(?=.*[^\da-za-z])(?=.*[@(#*){+=}/?~;,._]).{8,20}$
but contains following issue,
- accepting space
- can't add
-
character - repeating same number or letter more 3 times in row.
edit: fixed repeating character issues , have final expression like,
^(?!.*?(.)\1{3})(?!.* )(?=.*[a-z])(?=.*[a-z])(?=.*\d)(?!.*[:£€&"!'[\]%^\|<>$]).{8,20}$
but working on online tester [regexr][1]
tried following code generates runtime
- (bool)string:(nsstring *)text matches:(nsstring *)pattern{ nserror *error; nsregularexpression *regex = [nsregularexpression regularexpressionwithpattern:pattern options:0 error:&error]; nsarray *matches = [regex matchesinstring:text options:0 range:nsmakerange(0, text.length)]; return matches.count > 0;
}
Comments
Post a Comment