**question:**
Javascript regular expression password validation having special characters
url:http://stackoverflow.com/questions/12090077/javascript-regular-expression-password-validation-having-special-characters
```
var reg = /^(?=.*[0-9])(?=.*[!@#$%^&*])[a-zA-Z0-9!@#$%^&*]{6,16}$/;
```
> 說明
必須擁有數字和特殊字符,并且在6~16位之間
Without it, your current regex only matches that you have 6 to 16 valid characters, it doesn't validate that it has at least a number, and at least a special character. That's what the lookahead above is for.
`(?=.*[0-9])` - Assert a string has at least one number;
`(?=.*[!@#$%^&*])` - Assert a string has at least one special character.
> 學習
密碼需求:必須滿足大寫字母,數字,特殊字符中兩個條件。長度8~16