Regex to match a username

后端 未结 2 1684
生来不讨喜
生来不讨喜 2021-02-10 08:27

I am trying to create a regex to validate usernames which should match the following :

  • Only one special char (._-) allowed and it must no
2条回答
  •  失恋的感觉
    2021-02-10 09:09

    I think you need to use ? instead of +, so the special character is matched only once or not.

    ^(?=(?![0-9])?[A-Za-z0-9]?[._-]?[A-Za-z0-9]+).{3,20}

提交回复
热议问题