我試圖在密碼輸入上進行模式匹配,但不知何故,HTML聲稱存在不匹配,而JavaScript聲稱匹配。在regexr.com/7gmmi上測試我的正規表示式顯示一切正常...
我錯過了什麼?
<input id="password" type="password" placeholder="密码输入" pattern="/^(?!.*(.){1})(?=(.*[\d]){2,})(?=(.*[a-z]){2,})(?=(.*[A-Z]){2,})(?=(.*[\D\W\S]){2,})(?:[\d\w\S]){8,64}$/">
const patternPass = new RegExp(/^(?!.*(.){1})(?=(.*[\d]){2,})(?=(.*[a-z]){2,})(?=(.*[A-Z]){2,})(?=(.*[\D\W\S]){2,})(?:[\d\w\S]){8,64}$/); console.log(patternPass.test("FAGX@s#A2dred01sd")); /// true