[英]Validate.js ReGex not working as expected
我正在嘗試使用格式:模式:Validate.js 的功能來確保密碼滿足至少一個大寫、一個小寫、一個數字和一個特殊字符的要求,最小長度為 8 和最大為 20。存在和長度功能如預期。 有人有任何提示嗎?
password: {
presence: {
allowEmpty: false,
message: "is required",
admin: "required",
label: "Password*",
},
length: {
minimum: 8,
message: "must be at least 8 characters",
maximum: 20,
},
format: {
pattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!|@|#|\$|%|\^|&|\*])(?=.{8,20})/,
}
},
用
/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*]).{8,20}$/
解釋
--------------------------------------------------------------------------------
^ the beginning of the string
--------------------------------------------------------------------------------
(?= look ahead to see if there is:
--------------------------------------------------------------------------------
.* any character except \n (0 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
[a-z] any character of: 'a' to 'z'
--------------------------------------------------------------------------------
) end of look-ahead
--------------------------------------------------------------------------------
(?= look ahead to see if there is:
--------------------------------------------------------------------------------
.* any character except \n (0 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
[A-Z] any character of: 'A' to 'Z'
--------------------------------------------------------------------------------
) end of look-ahead
--------------------------------------------------------------------------------
(?= look ahead to see if there is:
--------------------------------------------------------------------------------
.* any character except \n (0 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
[0-9] any character of: '0' to '9'
--------------------------------------------------------------------------------
) end of look-ahead
--------------------------------------------------------------------------------
(?= look ahead to see if there is:
--------------------------------------------------------------------------------
.* any character except \n (0 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
[!@#$%^&*] any character of: '!', '@', '#', '$',
'%', '^', '&', '*'
--------------------------------------------------------------------------------
) end of look-ahead
--------------------------------------------------------------------------------
.{8,20} any character except \n (between 8 and 20
times (matching the most amount possible))
--------------------------------------------------------------------------------
$ before an optional \n, and the end of the
string
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.