JavaScript Regular Expression For Usernames No Spaces
javascript, regex
Solution
You can use `^[-\w\.\$@\*\!]{1,30}$`, where `1` and `30` are the bounds that you can change depending on how short the password needs to be at a minimum.
`\w` provides the Numbers, letters, and underscore coverage, followed by all the special chars you are allowing. Make sure to properly escape the special chars since a lot of them are used in actual regex parsing.
Using your examples provided (and some extra ones) you can see the regex working here.
Problem
I am seeking help with a JavaScript RegEx for user names. Basically I need the letters A-Z, digits, periods, dashes, underscores, dollar signs, at signs, the asterisk, and the exclamation point to be allowed and the username can be up to 30 characters long. No spaces or commas should be allowed for example. Allowed characters: ``` [a-zA-Z0-9] . - _ $ @ * ! ``` - User.name = passes - User name = fails - User,name = fails - usernameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee = fails