Skip to main content

jQuery Validation custom validation adding no space validation



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



Source: Tips4all

Comments

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?