Regex pattern to match at least 1 number and 1 character in a string

后端 未结 9 2441
既然无缘
既然无缘 2020-11-22 13:22

I have a regex

/^([a-zA-Z0-9]+)$/

this just allows only alphanumerics but also if I insert only number(s) or only

9条回答
  •  北海茫月
    2020-11-22 13:51

    Maybe a bit late, but this is my RE:

    /^(\w*(\d+[a-zA-Z]|[a-zA-Z]+\d)\w*)+$/

    Explanation:

    \w* -> 0 or more alphanumeric digits, at the beginning

    \d+[a-zA-Z]|[a-zA-Z]+\d -> a digit + a letter OR a letter + a digit

    \w* -> 0 or more alphanumeric digits, again

    I hope it was understandable

提交回复
热议问题