I have one form in which one input type whose value is "First Name". But this can be changed on onfocus function I want validation for this input field if it is blank or "First name"
I have two jQuery files jquery-1.4.2.min.js
& jquery.validate.pack.js
.
I have another jQuery file for this form:
jQuery(document).ready(function() {
jQuery("#frmRegister").validate({
errorElement:'div',
rules: {
Fname:{
required:true,
minlength: 2,
maxlength:30
}
},
messages: {
Fname:{
required: "Please enter first name",
minlength: "Required minimum 2 characters allowed",
maxlength: "Required maximum 30 characters allowed"
}
});
jQuery("#msg").fadeOut(5000);
});
In this file required:true
is working if value is blank but by default value is "First Name" so it does not work I want both if it is blank or it is "First Name".
<form name="frmRegister" id="frmRegister" method="post">
<ul class="reset ovfl-hidden join">
<li class="fall">
<label for="Fname">Full Name:</label>
<div class="fl">
<input type="text" class="form" id="Fname" name="Fname" value="First Name" onfocus="if(this.value=='First Name')this.value='';" onblur="if(this.value=='')this.value='First Name';" />
</div>
</li>
</ul>
</form>
Please reply as early as possible.
Thank you.
You can use required rule with Callback and check for equality with First Name before returning
Did u try the adding custom validation ]
Pls note i have added example
You should create custom validation rules for such cases as described here: jquery.validation - how to ignore default values when validating mandatory fields
this is my code it's working properly: try this