This is for validating usernames on my system.
Every username can include these symbols “.-_”, but the words separated by the mentioned symbols cannot be digits only.
An example would be
Invalid:
123.as-as123
123.AS-aS123
Valid:
a123.as-as123
A123.AS-aS123
I believe this will work, if I understand your requirements correctly:
It matches zero or more groups of letters/numbers ending with
.,-, or_and requiring at least one letter. Then it matches a final group of letters/numbers, requiring at least one letter.It is case insensitive (that is what the
iat the end does), so it will match uppercase as well. (This syntax works at least in Perl and PHP. In other languages, you might have to apply this option in a slightly different way, but case insensitive is always available).One might be tempted to shorten it like this:
However, that is less desirable, because making the
[.\-_]optional gives it too much flexibility in the ways it can try to match. It will probably have to run through a huge number of cases on a pattern that fails.