首页 文章

javascript regex alphanumeric在列表1的字母

提问于
浏览
0

我正在寻找一个使用Javascript的字母数字正则表达式,必须有atlist 1字母,所以字符串不能是所有数字 . 666 =无效a666 =有效

试图寻找像这样的正则表达式在整个网络找不到一个 . 我希望你能帮助我 .

2 回答

  • 0
    ^(?![0-9]+$)[a-zA-Z0-9]+$
    

    试试这个 . 这将确保你至少有一个数字通过 negative looahead 参见演示 .

    https://regex101.com/r/tX2bH4/43

    NODE                     EXPLANATION
     --------------------------------------------------------------------------------
      ^                        the beginning of the string
    --------------------------------------------------------------------------------
      (?!                      look ahead to see if there is not:
    --------------------------------------------------------------------------------
        [0-9]+                   any character of: '0' to '9' (1 or more
                             times (matching the most amount
                             possible))
    --------------------------------------------------------------------------------
       $                        before an optional \n, and the end of
                             the string
    --------------------------------------------------------------------------------
      )                        end of look-ahead
    --------------------------------------------------------------------------------
      [a-zA-Z0-9]+             any character of: 'a' to 'z', 'A' to 'Z',
                           '0' to '9' (1 or more times (matching the
                           most amount possible))
    --------------------------------------------------------------------------------
      $                        before an optional \n, and the end of the
                           string
    
  • 0

    使用基于前瞻性的正则表达式 .

    ^(?=.*?[a-zA-Z])[a-zA-Z\d]+$
    

    开头的正面预测 (?=.*?[a-zA-Z]) 断言要匹配的字符串必须包含至少一个字母 . 如果是,则仅匹配一个或多个字母或数字 . ^ 声称我们在开始时 $ 指的是一行的结尾 .

    DEMO

相关问题