Strip that checks if added username can be a username
Hello, does anyone know how to do a small script which checks that a username can be a username.
Im talking about the special charactes and spaces which can't be used when creating a username. So a user writes: "kevin little" in this case this can't be a username as it contains space. or "kevin\little" in this case this can't be a username as it contains special character '\'. or "kevin_little" in this case it can be a username as there are only accepted charactes. If someone knows how to do this please let me know. Thank you. |
You could use bash regular expressions:
Code:
if [[ "$NAME" =~ ^[a-z][-a-z0-9]*$ ]]; then echo 'okay'; fi |
OK, but this is only normal characters, what about '-' '_' or '.' ?
|
Hi,
Officially this is the legal template for a linux/unix username: [a-z_][a-z0-9_-]* The only character missing in post #2 is a _ (twice) ^[a-z][-a-z0-9]*$ should be ^[a-z_][-a-z0-9_]*$ Hope this helps. |
Yes, it helps.
Thank you very much for the help! |
You're welcome :)
|
All times are GMT -5. The time now is 04:38 AM. |