I am trying to validate a password field using regex in Swift/iOS the feature of the passwords are:
- 1 uppercase at least
- 1 number at least
(other than that lowercase and symbols are allowed of course, but those are the required)
this is my current RegEx format:
let passwordRegex = "^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[*.!@$%^&(){}[]:;<>,.?/~_+-=|\\])$"
this is my password: Test@123
When I run the simulator it errors with the following:
Thread 1: "Can't do regex matching, reason: Can't open pattern U_REGEX_MISSING_CLOSE_BRACKET (string Test@123, pattern ^(?=.[0-9])(?=.[a-z])(?=.[A-Z])(?=.[*.!@$%^&(){}[]:;<>,.?/~_+-=|\])$, case 0, canon 0)"
What is wrong whith my RegEx string?
/and i dont know if thats the issue...^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[*.!@$%^&(){}[]:;<>,.?\/~_+-=|\\])$U_REGEX_MISSING_CLOSE_BRACKETsignal exactly that). Besides, once you fix that, you should also make sure you consume the whole string, keep the hyphen at the end of the character class, and use principle of contrast (and raw string literal):let passwordRegex = #"^(?=\D*\d)(?=[^a-z]*[a-z])(?=[^A-Z]*[A-Z])(?=[^*.!@$%^&(){}\[\]:;<>,.?/~_+=|\\-]*[*.!@$%^&(){}\[\]:;<>,.?/~_+=|\\-]).*"#