Regular expression to validate username

后端 未结 10 972
温柔的废话
温柔的废话 2020-11-28 19:27

I\'m trying to create a regular expression to validate usernames against these criteria:

  1. Only contains alphanumeric characters, underscore an
10条回答
  •  生来不讨喜
    2020-11-28 20:13

    ^(?=.{8,20}$)(?![_.])(?!.*[_.]{2})[a-zA-Z0-9._]+(?

    If your browser raises an error due to lack of negative look-behind support, use the following alternative pattern:

    ^(?=[a-zA-Z0-9._]{8,20}$)(?!.*[_.]{2})[^_.].*[^_.]$
    

提交回复
热议问题