jqueryvalidation no space customization

Posted by Ken on Stack Overflow See other posts from Stack Overflow or by Ken
Published on 2011-11-12T01:47:58Z Indexed on 2011/11/12 1:50 UTC
Read the original article Hit count: 330

i have a form where the user can update his name and last name. i use jquery validation to validate the form. how can i validate if the user put spaces?

here's what i have:

<script>
$(document).ready(function(){   
  $('#submit').click(function() {
  var valid = $("#myform").valid();
  if(!valid) {
    return false;
  }
  $.ajax({
    type: "POST",
    url: 'save',
    data:  $('#myform').serialize(),
    dataType: 'json',
    cache: false,
    success: function(result) {
      // redirect to another page
    }
  });
  });
  });
</script>

</head>
<body>


<form id="myform" method="post" action="">
<fieldset>
<legend>update name</legend>
<p>
 <label for="fname">Name</label>
 <em>*</em><input id="fname" name="fname" size="25" class="required" minlength="2" />
</p>
<p>
 <label for="lname">Last Name</label>
 <em>*</em><input id="lname" name="lname" size="25" class="required" minlength="2" />
</p>
<p>
 <input id="submit" type="submit" value="Submit"/>
</p>
</fieldset>
</form>

thanks

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jquery-validation-plugin