Objective-C RegEx-Password-Check is always true

I want to check the password's complexity with regular expression. But it returns always true?

The password's complexity is the following. Allowed are:

  • A-Z
  • a-z
  • 0-9
  • special characters: - _ , ; . : # + * ? = ! § $ % & / ( ) @
  • No blank characters

Here is my code:

NSString *regExPwd = @"[a-zA-Z_0-9\\-_,;.:#+*?=!§$%&/()@]+";
NSPredicate *pwdCheck = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regExPwd];
bool isValid = [pwdCheck evaluateWithObject:txtPassword.text];

Hope you can help me once again :)

Answers


You should require that there are only allowed characters from the beginning to the end:

NSString *regExPwd = @"^[a-zA-Z_0-9\\-_,;.:#+*?=!§$%&/()@]+$";

Need Your Help

Using lock(obj) inside a recursive call

c# .net multithreading locking

As per my understanding a lock is not released until the runtime completes the code block of the lock(obj) ( because when the block completes it calls Monitor.Exit(obj).