I am trying this for the first time.I need to set some validations for my sign up page .It has 3 fields:name,email and password.I have successfully set the validations for the first two fields but things are getting a bit messy with the third field.Here is my code for the third field:
NSString *string = @"1Aa1A111";
NSString *format = [NSString stringWithFormat:@"([A-Z])*(([a-z])+ ([0-9])+([A-Z])+)([A-Z])*"];
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",format];
BOOL match = [pred evaluateWithObject:string];
Now when I tried to google the answer I'm getting a whole lot of answers that I can't understand , specially "?=" in regular expression.I tried to check the functionality of "?=" but my code crashes everytime.Here is my code for checking the functionality of "?=" :
NSString *string = @"a";
NSString *format = [NSString stringWithFormat:@"?=.*[a-z]"];
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",format];
BOOL match = [pred evaluateWithObject:string];
NSLog(@"%d",match);
The validations that I need for my password are:
- Atleast one lowercase.
- Atleast one uppercase.
- Atleast a digit.
- Atleast a special character.