I am using jquery validation plugin
I added a custom method using addmethod which in turn calls another method to check for valid UK telephone number
here is my code (simplified):
html
<form id="myform">
<label for="field">Required, telephone: </label>
<input class="required" id="field" name="field" />
<br/>
<input type="submit" value="Submit" />
</form>
jquery
$(document).ready(function(){
$("#myform").validate({
rules:{
field:{
required:true;
UKTelNumber:true
}
}
});
});
jQuery.validator.addMethod("UKTelNumber", function(value,element) {
if (!checkUKTelephone (value)) {
alert (telNumberErrors[telNumberErrorNo]);
return false;
}
else {
return true
}
},jQuery.validator.format(telNumberErrors[telNumberErrorNo]));
The function checkUKTelephone
sets the value of var telNumberErrorNo
according to the type of error.
All the error messages are there in an array telNumberErrors
.
Now my requirement is that how to show those error messages that is being alerted now.
passing jQuery.validator.format(telNumberErrors[telNumberErrorNo])
as message (third option) of addMethod is not helping.
I also tried passing only this telNumberErrors[telNumberErrorNo]
but its showing only one message every time i.e message contained in telNumberErrors[0]
plz help me
Thanks in advance