How to remove space and limit special characters using jquery?
I am creating a registration form on my website. I want to do some validation with the username that
- The user cannot have a space,
- The username cannot contain any special characters other than a period (.), As gmail follows its registration form.
I am using jquery in my application, can anyone tell me how to implement the above two validations using jquery ?? I remember these two basic checks for username, please suggest if you know any other?
thanks
+1
a source to share
5 answers
When I checked the answers, I saw that the space was allowed. So I'm improving the regex for others who will be reading this question:
You need to do the following:
if (!$('#uname').val().match(/^[a-z0-9_-]{3,15}$/)) {
alert("Please, use standard characters.");
}
Regular expression description:
^ - beginning of line
[a-z0-9_-] - match characters and characters in the list, az, 0-9, underscore, hyphen
{3.15} - Length of at least 3 characters and maximum length of 15
$ - End of line
0
a source to share