dra*_*onn 5 html javascript css
我想知道如何使用方括号 {} [] () 和其他类似“'”的特殊字符部分添加到我在下面尝试的唯一字符中,但是由于某种原因,当我添加另一个这些字符时,它停止工作.
<-- works but does not have any brackets or quotes for special character-->
<form acton = "#">      
    <input type="password" id="newPass" required
      pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*?[0-9])(?=.*?[!@#$%^&*+`~=?\|<>/]).{8,}"
    <button>submit</button>
</form>
上面的部分有效但没有引号或更多特殊字符
下面的代码有括号但不起作用
<-- does not work (if you do not enter special character user will be able to submit but it does not have any brackets -->
<form acton = "#">      
    <input type="password" id="newPass" required
      pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*?[0-9])(?=.*?[~`!@#$%^&*()-_=+[]{};:'.,"\|/?><]).{8,}"
    <button>submit</button>
</form>
这也不起作用(来自答案)
<form acton = "#">      
    <input type="password" id="pass" required
      pattern="(?=.*\d)(?=.*[a-z])(?=.*?[0-9])(?=.*?[~`!@#$%\^&*()\-_=+\[\]{};:\'.,\"\\|/?\>\<]).{4,}">
    <button>submit</button>
</form>
我正在寻找使底部(带括号和我包含的所有特殊字符的部分)起作用的答案。
由于它是正则表达式,因此内部的所有字符[.....]都是允许的,因此您应该在其中添加括号。您可以使用转义字符来完成此操作(因为括号在正则表达式中起作用)。因此只需将\]和添加\[到 内部允许的字符中即可[.....]。
尝试:
<input type="password" name="pw" pattern="(?=.*?[#?!@$%^&*-\]\[])"
顺便说一句..我建议使用正则表达式备忘单,它将在验证任务中为您提供很大帮助。
至于你的编辑:
和"需要'转义。虽然\" \'不起作用,但您可以使用\x27and代替,它们是ascii 表中和 的\x22十六进制表示形式。"'
尝试:
<form acton = "#">      
        <input type="password" id="pass"  required pattern = "(?=.*\d)(?=.* 
     [a-z])(?=.*?[0-9])(?=.*?[~`!@#$%\^&*()\-_=+[\]{};:\x27.,\x22\\|/?><]).{4,}">
        <button>submit</button>
</form>
| 归档时间: | 
 | 
| 查看次数: | 2133 次 | 
| 最近记录: |