有人可以在密码中为我解释模式或正则表达式的语法吗?

时间:2018-09-20 07:29:54

标签: html regex syntax passwords

我已经开始研究Web开发,由于无法完全理解模式或正则表达式,或者由于如何将规则放入其语法中,我被卡住了,有人可以向我解释吗?

<label for="password2">Password: </label>
<input id="password2" type="password" placeholder="password here"
pattern="[0-9a-zA-Z]{8,12}"
title="Please enter a password 8-12 alpha numeric characters" required>

在上面的示例中,我已经了解了以下模式:
0-9 <-您可以在0到9之间插入数字
a-z <-您可以从a到z插入小写字母
A-Z <-您可以将大写字母从A插入到Z
{8,12} <-密码必须至少包含8个和12个字符

到目前为止,很好。
但是如何添加规则,例如:
1)请至少插入一个或多个符号,例如!,@,#,$
2)输入至少一个大写字母或更多
3)输入至少3个数字
4)排除以下符号:&,*

在W3Schools中,他们有以下示例:

<form action="/action_page.php">
Password: <input type="password" name="pw" pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}" title="Must contain at least one number and one uppercase and lowercase letter, and at least 8 or more characters">
<input type="submit">
</form>

什么是它做什么?
1)(?=。 \ d)
2)(?=。
[a-z])<-这必须是“至少使用一个小写字母”,但是如何定义所需的小写字母呢?
3)(?=。* [A-Z])<-这是大写字母

另一个例子是来自MDN
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/password

<label for="ssn">SSN:</label>
<input type="password" id="ssn" inputmode="numeric" minlength="9" maxlength="12"
    pattern="(?!000)([0-6]\d{2}|7([0-6]\d|7[012]))([ -])?(?!00)\d\d\3(?!0000)\d{4}"
    required autocomplete="off">
<br>
<label for="ssn">Value:</label>
<span id="current"></span>

使用以下规则: (?!000)([0-6] \ d {2} | 7([0-6] \ d | 7 [012]))([--])?(?! 00)\ d \ d \ 3 (?!0000)\ d {4}“

有人可以分解并解释吗? 上面的语法是html还是其他?

很长的帖子,我很抱歉,您不必回答我所问的所有问题。 我只想有一个清楚的了解。 我知道我可能不需要使用上面的任何内容,因为您不能信任前端的任何用户,并且我可能在上面的规则中使用JavaScript。
“直到被证明是无辜的,所有用户才有罪”

谢谢。

0 个答案:

没有答案