MSU_Bulldog
MSU_Bulldog

Reputation: 3519

RegexKitLite iOS: Password validation - must include one number

I am using RegexKitLite in my iOS app and I need to do validation on a form for a password textfield. The rule I am going by is that the password should include at least one number, one uppercase letter, and two symbols. Could someone help me out with this? This is what I've found on the internet and tried (it doesn't work, of course):

if([password.text isMatchedByRegex:@"^(?=.*[0-9])(?=.*[A-Z])(?=.*\d)(?=.*[_\W]{2,}).+$"]) {
    // do stuff
}

Upvotes: 0

Views: 165

Answers (1)

MSU_Bulldog
MSU_Bulldog

Reputation: 3519

I figured out an answer, a lot more simple than trying to cram all those regular expressions into one big one.

if([password.text isMatchedByRegex:@"[0-9]+"] // contains at least 1 number
 && [password.text isMatchedByRegex:@"[A-Z]+"] // contains at least 1 Capital letter
 && [password.text isMatchedByRegex:@"[^a-zA-Z0-9]{2,}"]) // contains 2 symbols
{ 
     // do stuff
}

Hope this can be helpful to someone!

Upvotes: 1

Related Questions