I need a Regular Expression for Javascript that checks if a password is correct only when
Examples:
I tried using
var Reg = /^(?=.*\d)(?=.*[A-Za-z])[0-9A-Za-z-_]{4,12}$/;
It works in PHP, but not in Javascript, any suggestions?
Put the hyphen at the end of the character class:
var Reg = /^(?=.*\d)(?=.*[A-Za-z])[0-9A-Za-z_-]{4,20}$/;
You can also shorten that character class:
var Reg = /^(?=.*\d)(?=.*[A-Za-z])[\w-]{4,20}$/;
Also, you said 20 characters, not 12. Right?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.