0

I have this regex I'm using for username validation, but I don't understand regex very well.

Anyone can help me change this to allow hyphens please?

/^(?!.*[_.]$)(?=.{8,30}$)(?![_.])(?!.*[_.]{2})[a-zA-Z0-9._]+$/
Stefan S
  • 23
  • 4
  • 2
    `[a-zA-Z0-9._]` => `[a-zA-Z0-9._-]` – Wiktor Stribiżew Jun 18 '20 at 20:23
  • Hyphens in Classes `[chars]` are a special character that is called a `range operator` like `A-Z` all chars from A to Z. To match a hyphen literal when it's not a range, just escape it like `[A-Z\-0-9]` –  Jun 18 '20 at 20:28

0 Answers0