Reputation: 330
I am using this plugin. Is there any way to validate number of words?
For eg in "firstname" there shouldn't be any spaces allowed. So, the validating criteria shud be like this => maxwords="1"
Is there any way to do this currently? If not, what should i do to get this going.
Thanks
Upvotes: 0
Views: 642
Reputation: 98738
Use the addMethod()
method to create your custom rule.
Example:
jQuery.validator.addMethod("maxwords", function(value, element, params) {
// your function to count words goes in here
// use any of these arguments in your function: value, element, params
// value => the present value of the field being tested
// element => the present field being tested
// params => the parameters passed in when you declare the rule.
// example: // maxwords: 1 // params[0] would be 1
// return true // if the field passes validation
// return false // if the field fails validation and the message below will display
}, "Please enter at least {0} words."));
Upvotes: 2