我正在尝试制作一个简单的密码验证器,以确保它是任何类型的8个字符,并且没有空格。我是regex的新手,但以下是我所拥有的:
<form>
<input type="password" id="password" pattern="(?!*s).{8}">
<input type="submit" value="submit">
</form>
pattern="[^s]{8}"
-任何非空格字符的八个字符。
[^ - Negated set. Match any character that is not in the set.
s - Whitespace. Matches any whitespace character (spaces, tabs, linebreaks).
] - End of negated set
{8} - Quantifier. Match 8 of the previous token.
^
(字符串的开头(和$
(字符串的结尾(在输入模式中不是必需的,因为它们是隐含的。