0

我需要帮助想出一个用于验证密码的 javascript 正则表达式。
密码(8 个字符长,至少一个非字母字符)
确保用户在开头或结尾没有空格也很有用

4

2 回答 2

1

这是一个与您要求的模式相匹配的模式

pattern = /^(?=.*[^a-z])\S.{6}\S$/i;

于 2013-11-15T02:20:39.783 回答
0

Depends how 'complicated' you want to get but I find either if the following useful:

/*
    No more than 4 same characters
    - One digit
    - One uppercase
    - One lowercse
    - One 'punctuation' mark
    - between 8 and 20 characters
*/                                  
re = /^(?!.*(.)\1{4})((?=.*[\d])(?=.*[A-Z])(?=.*[a-z])(?=.*[^\w\d\s])).{8,20}$/;

/*
    - One Digit
    - One lower case
    - One upper case
    - Maximum 2 repeating char
    - between 6 and 20 characters
*/                                  
re = /^(?!.*(.)\1{2})((?=.*[a-z])(?=.*[A-Z])(?=.*\d)).{6,20}$/;

These are not my regexp's as I found them on the web but can't remember where.

于 2013-11-15T02:13:44.970 回答