Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expression For Password in iPhone?

I am pretty much weak in creating Regular Expression. So I am here.

I need a regular expression satisfying the following.

  1. Atleast one numeric value and Atleast one alphabet should be present for the password
  2. Minimum 6 Maximum 32 characters should be allowed.
like image 716
ipraba Avatar asked Nov 27 '22 06:11

ipraba


2 Answers

 -(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.

like image 128
Rayfleck Avatar answered Dec 01 '22 02:12

Rayfleck


Try this:

^(?=.*\d)(?=.*[A-Za-z]).{6,32}$
like image 21
Oleks Avatar answered Dec 01 '22 02:12

Oleks