Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

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

NSString *nameRegex =@"My RegEx"; 
NSPredicate *nameTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", nameRegex]; 
validationResult=[nameTest evaluateWithObject:password];

These are the conditions

  1. It should contain letters and numbers

  2. Minimum 7 characters Max 32 characters

  3. No Space

  4. No Symbols

Please Help..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here's how you do it !

/^[a-zA-Z0-9]{7,32}$/

Don't forget the "beginning to end" markers.

For the record, if you want it the string to definitely include both letters and digits, there is no way to do that with one regex. (In fact, mathematically you could do it, but the regex would be enormous.)

Simply run the above check, and THEN ALSO CHECK that it contains a letter: /[a-zA-Z]/

And THEN ALSO TEST that it contains a digit: /[0-9]/

That's the easiest way.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...