html - jquery validation for field with default value -
this question has answer here:
http://jqueryvalidation.org/files/demo/
i using above plugin jquery validation of registration form
it working properly, in form there 1 field name "domain" default value has been set "www." user have write other part domain.
so practically not blank time, not validating if user left filed default value, here jquery , html code
<script> $().ready(function() { $("#frm").validate({ rules: { domain: "required", uname: "required", password:'required', cpassword:'required', fname:'required', lname:'required', bussname:'required', city:'required', state:'required', pincode:'required', country:'required', phone1:'required', email: { required: true, email: true }, code:'required', }, messages: { domain: "please enter domain name", uname: "please enter user name", password: "please enter password", cpassword:'please confirm password', fname:'please enter first name', lname:'please enter last name', bussname:'please enter practice', city:'please enter city', state:'please enter state', pincode:'please enter zip code', country:'please select country', phone1:'please enter phone', email: 'please enter email address', code: 'please enter security code', } }); }); </script>
my html form
<form name="frm" id="frm" action="ezregistration2.php" method="post"> <input name="domain" type="text" id="domain" value="www." size="40" class="tb7" /> <input name="uname" type="text" id="uname" value="" size="40" class="tb7" onkeyup="countchars(this);" /> <input name="password" type="password" id="password" size="40" class="tb7"> <input name="cpassword" type="password" id="cpassword" size="40" class="tb7"> <input name="fname" type="text" id="fname" value="" size="40" class="tb7" > <input name="lname" type="text" id="lname" value="" size="40" class="tb7" > <input name="bussname" type="text" id="bussname" value="" size="40" class="tb7"> <input name="address1" type="text" id="address1" value="" size="40" class="tb7"> <input name="address2" type="text" id="address2" value="" size="40" class="tb7"> <input name="city" type="text" id="city" value="" size="40" class="tb7" > <input name="state" type="text" id="state" value="" size="40" class="tb7" > <input name="pincode" type="text" id="pincode" value="" size="40" class="tb7" > <select name="country" id="country" class="tb7" style="width:225px;"> <option value="afghanistan">afghanistan</option></select> <input type="text" name="phone1" size="40" id="phone1" value="" onkeypress="return nonumbers(event)" class="tb7"> <input name="email" type="text" id="email" value="" size="40" class="tb7"> <input type="text" name="code" id="code" size="8" class="tb7" style="width:100px" /> <input name="submit" type="image" src="homeimages/submit.jpg" class="submitbtn" style="outline:none;" /> <input type="hidden" name="sub" value="1"> </form>
is there anyway should not allow default value upon validation ?
add before $("#frm").validate({
jquery.validator.addmethod("domain", function(value, element){ return this.optional(element) || value != "www."; }, "please enter domain name");
and in rules change domain: "required",
to
domain: { required: true, domain: true },
Comments
Post a Comment