views:

1926

answers:

4

I am creating a signup form in my website. I want to implement some checkup with username, which are

  • username can't have any space,
  • username can't have any special characters other than dot (.) as gmail is doing in thier signup form.

I am using jQUERY in my app, can anyone tell me how to implement above listed two checkups using jquery ?? I remember these two main checkups for username please suggest if you knows any other?

Thanks

+1  A: 

First see here in another entry in SO, jquery-validate-how-to-add-a-rule-for-regular-expression-validation.

if you need other ideas try here for an example using PHP and an AJAX call using jQuery.

You can also check out this page for a another jQuery solution.

Dror
+4  A: 

Have a look at the validation plug-in.

Whatever you do, validate the username at the server side too.

kgiannakakis
Very good point - you shouldn't rely solely on client side validation as it can easily be by-passed +1.
Ian Oxley
+1  A: 

You can check that using javascript regex:

if ($('#username').val().match(/^(\w)+[\w\d\.]*/)) {
  // everyting is ok
}else {
  // something is wrong
}
Uzbekjon
A: 

Hi guyz, I tried out following jquery script by studying the links (this one) given by @Dror to check for wrong characters in username,

if (!$('#uname').val().match("^[a-z0-9'.\s]{1,50}$")) {
    //not a correct username
}

Thanks

Prashant