I am pretty much weak in creating Regular Expression. So I am here.
I need a regular expression satisfying the following.
-(BOOL) isPasswordValid:(NSString *)pwd {
if ( [pwd length]<6 || [pwd length]>32 ) return NO; // too long or too short
NSRange rang;
rang = [pwd rangeOfCharacterFromSet:[NSCharacterSet letterCharacterSet]];
if ( !rang.length ) return NO; // no letter
rang = [pwd rangeOfCharacterFromSet:[NSCharacterSet decimalDigitCharacterSet]];
if ( !rang.length ) return NO; // no number;
return YES;
}
This is clearly not a regex, but imo regex is overkill for this.
Try this:
^(?=.*\d)(?=.*[A-Za-z]).{6,32}$
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