I am wrestling with my regex. I want to allow only one letter and numbers and one point in one username, and 2 to 20 characters, so I thought about something
[0- 9a-zA-Z] {2,20}
But then 21 characters are also ok, and that is not what I want
I recommend that you make two checks - for content based on one more fact for length, you probably want a point on the name rather than any number Are there. I think the name like usernames
and user.name
are allowed.
It should get content (but this allows at least):
^ \ w + (\. \ W +)? $
If you do not want underscores, you can enter the 0- 9A-GAA-ZE + +
\ w +
On. To understand, it will match any string in which there will be one or more letter characters, after which after one or more word characters after exactly 0 or 1. It should also match the beginning and end of the string, that is, no other character is allowed in the string.
Then you only need to get length with a simple length check.
Comments
Post a Comment