what is the wrong with this Jquery form validation -


i trying validate form element 3 condition using jquery.

this code -

var valid = true, errormessage = "";  if ($('#name').val()) {     if ($('#name').val().length > 60 || $('#name').val().length < 3)  {          errormessage  = "length of name must between 3 , 60.\n";         valid = false;     } else {         var rege = /^[a-z]([a-z_])+$/i;         if(!rege.test(!$('#name').val())){                 errormessage  += "please enter valid name.\n";                valid = false;         }     } } else {     errormessage  += "please enter name \n";     valid = false;    } 

if name field empty should display 'please enter name'.

if field not empty , length < 3 or > 60 should display 'length of name must between 3 , 60'.

finally should check user name valid or not. if not valid 'please enter valid name' should display.

my problem when entering valid user name going message - 'please enter valid name.'

can tell wrong have gone?

note : name can have uppercase letters , lowercase letters.

fiddle

any ideas appreciated. thank you.

it looks fine me exception unwanted ! in

        var rege = /^[a-z]([a-z\s])+$/i;         if(!rege.test($('#name').val())){ // ! before $('#name').val() not required             errormessage  += "please enter valid name.\n";             valid = false;         } 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -