Reputation: 306
I use VeeValidate and regex for password with requirement: At least two characters from uppercase, lowercase, numbers, and symbols.
v-validate="required|min:8|max:20|regex:/^(?=(.*?[a-z].*?[A-Z])|(.*?[a-z].*?[0-9])|(.*?[a-z].*?[!@#$%^&*()_+])|(.*?[A-Z].*?[0-9])|(.*?[A-Z].*?[!@#$%^&*()_+])|(.*?[0-9].*?[!@#$%^&*()_+])).*$/"
But the browser displays an error message:
[Vue warn]: Error in callback for watcher "value": "SyntaxError: Invalid regular expression: //^(?=(.?[a-z].?[A-Z])/: Unterminated group"
Thanks for support.
Upvotes: 0
Views: 1268
Reputation: 306
We should use the object format of the rules instead.
Heads up!
You should not use the pipe '|' or commas ',' within your regular expression when using the string rules format as it will cause a conflict with how validators parsing works. You should use the object format of the rules instead.
v-validate="{required: true, min:8, max:20,
regex:/^(?=(.*?[a-z].*?[A-Z])|(.*?[a-z].*?[0-9])|(.*?[a-z].*?[!@#$%^&*()_+])|(.*?[A-Z].*?[0-9])|(.*?[A-Z].*?[!@#$%^&*()_+])|(.*?[0-9].*?[!@#$%^&*()_+]))/}"
Update the latest regex: At least two characters from uppercase, lowercase, numbers, and symbols.
v-validate="{required: true, min:8, max:20,
regex:/^(?=(.*?[a-z].*?[A-Z])|(.*?[A-Z].*?[a-z])|(.*?[a-z].*?[0-9])|(.*?[0-9].*?[a-z])|(.*?[a-z].*?[!@#$%^&*()_+])|(.*?[!@#$%^&*()_+].*?[a-z])|(.*?[A-Z].*?[0-9])|(.*?[0-9].*?[A-Z])|(.*?[A-Z].*?[!@#$%^&*()_+])|(.*?[!@#$%^&*()_+].*?[A-Z])|(.*?[0-9].*?[!@#$%^&*()_+])|(.*?[!@#$%^&*().*?[0-9]_+])).*$/}"
Upvotes: 1