Regular iPhone Password Schedules

I'm pretty weak at creating a regex. So here I am.

I need a regular expression satisfying the following.

  • At least one numeric value and at least one character must be present for the password
  • Minimum 6 Maximum 32 characters must be allowed.

thanks

+4
source share
5 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 regular expression, but imo regex is superfluous for this.

+18
source

Try the following:

 ^(?=.*\d)(?=.*[A-Za-z]).{6,32}$ 
+10
source

Without using any third-party libraries like Regexkit, you can check your requirements as follows:

  if ([[password rangeOfCharacterFromSet: [ NSCharacterSet alphanumericCharacterSet]] && [password rangeOfCharacterFromSet: [NSCharacterSet characterSetWithCharactersInString: @"0123456789"]] && (6 < [password length]) && [password length] < 32)) { NSLog(@"acceptable password"); } 
+2
source

Here you can find the useful regexp cheatsheet command, which also provides some examples. One of them really looks like your needs (6th place in the "Example template" field) :)

+1
source

The following must comply with the minimum / maximum characters, at least 1 alpha and 1 numeric character requirements:

 ^(?=.{6,32}$)(?=.*\d)(?=.*[a-zA-Z]).*$ 
+1
source

Source: https://habr.com/ru/post/1346236/


All Articles