简体   繁体   English

密码的表达式正则

[英]Expression regular for password

I need the correct regular expression pattern, for checking input text in HTML matching this format:我需要正确的正则表达式模式,用于检查 HTML 中匹配此格式的输入文本:

  • Start with a capital letter以大写字母开头

  • End with the character $以字符 $ 结尾

  • Between the initial capital letter and the final dollar character there may be:在首字母大写和最后的美元字符之间可能有:

    1. Letter between a and z (both included) uppercase or lowercase a 和 z 之间的字母(均包括在内)大写或小写
    2. Digit from zero to nine (two included)数字从零到九(包括两个)
    3. The underscore character ( _ )下划线字符 (_)

Example: B4rc3l0nA$, Fr4_nc3$, A$示例: B4rc3l0nA$, Fr4_nc3$, A$

I think I have to add anchors at the beginning and at the end, but I don't know how to join everything so that the complete regular expression remains.我想我必须在开头和结尾添加锚点,但我不知道如何加入所有内容,以便保留完整的正则表达式。

<input type="text" placeholder="Your password" pattern="^\[a-z]i\s-\s[0-9]{2}\([a-z]{1,3})$" required>

You can use this regular expression.您可以使用此正则表达式。

^[A-Z]\w+?\$$
  1. ^[AZ] meaning start with capital character as first letter. ^[AZ]表示以大写字母开头。
  2. \w+? any letter or number or underscore任何字母或数字或下划线
  3. \$$ dollar sign at the end. \$$美元符号在末尾。

 const checkPassword = (password) => { return /^[AZ]\w+?\$$/.test(password) } console.log(checkPassword("B4rc3l0nA$")) console.log(checkPassword("Fr4_nc3$")) console.log(checkPassword("Fr4_nc3")) console.log(checkPassword("fr4_nc3$")) console.log(checkPassword("Ab!!@@ÅÆØ}$"))

FOR TESTING用于检测

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM