我有3个验证器方法来验证表单域。对于我必须验证的每个表单字段,我需要始终调用这3个验证器。是否可以编写一个验证器方法,在内部调用这3个方法并返回适当的错误?Jquery - 在一个大的验证器方法内调用多个验证器
/*
* Do not allow a name to include only underscores.
*/
jQuery.validator.addMethod('notallunderscores', function(value, element)
{
value = value.replace(/\_/g,'');
return this.optional(element) || value.length > 0;
}, "Enter more than only underscore characters.");
/*
* Do not allow a name to include only hyphens.
*/
jQuery.validator.addMethod('notallhyphens', function(value, element)
{
value = value.replace(/\-/g,'');
return this.optional(element) || value.length > 0;
}, "Enter more than only hyphens.");
/*
* Do not allow a name to include leading or trailing spaces.
*/
jQuery.validator.addMethod('notrailingorleadingspaces', function(value, element)
{
return this.optional(element) || ! value.match(/^ .*|.*\ $/g);
}, "Please remove any leading or trailing spaces.");
我要找的验证应该是这样的:
/*
* Call each of the above validator methods and return appropriate error.
*/
jQuery.validator.addMethod('validateformfield', function(value, element)
{
//Call the above 3 validator methods
//Return the appropriate error returned by the above validators.
}, "Return the error message from the failed validator.");