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

后端 未结 9 2424
既然无缘
既然无缘 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:58

    The accepted answers is not worked as it is not allow to enter special characters.

    Its worked perfect for me.

    ^(?=.*[0-9])(?=.*[a-zA-Z])(?=\S+$).{6,20}$

    • one digit must
    • one character must (lower or upper)
    • every other things optional

    Thank you.

提交回复
热议问题