-1

I have an input field on my website which uses pattern matching in the HTML It needs to have - Lowercase a-z (not upper) - All numbers (0-9) - Allows underscores (_) but NOT spaces - Minimum of 4 characters with a max of 12. - Does not allow special characters such as @, #, $, %, ^, * etc.

Right now I have pattern="(?=.*[a-z0-9_]).{4,12}" The problem seems to be that it does allow special characters.

2 Answers2

1

You can use a simple regex like this:

[a-z\d_]{4,12}
Federico Piazza
  • 28,830
  • 12
  • 78
  • 116
0

Try:

pattern="[a-z0-9_]{4,12}"

I don't think you need the ?=, .* or .

user156213
  • 718
  • 4
  • 12