I don't know much regex and when it comes to username it becomes a little tricky, so I request from my fellow programmers to help me validate a username with respect to certain conditions.
- Username can only contain letters, numbers, periods and underscores.
- Username can start and end with underscores but never with periods. (for security reasons)
- Username length should be between 4 and 20 characters.
- Spaces are not allowed
Examples of valid and invalid usernames:
josh valid
.josh_ invalid
_josh. invalid
_josh_123.brad valid
josh brad invalid
I have already searched and the answer I find didn't quite help. This is my regex for now:
RegExp('^(?=[A-Za-z0-9._]{4,20}$)[^_.].*[^_.]');
Thanks in advance