分类: 系统运维
2012-08-22 16:12:55
转自
addMethod( name, method, [message] )Add a custom validation method. It must consist of a name (must be a legal javascript identifier), a javascript based function and a default string message.The arguments to the callback are:
* the current value of the validated element
* the element to be validated
* parameters specified for the method,e.g. for min: 5 the parameter is 5, for range: [1, 5] its [1, 5]
Please note: While the temptation is great to add a regex method that checks it's parameter against the value, it is much cleaner to encapsulate those regular expressions inside their own method. If you need lots of slightly different expressions, try to extract a common parameter.
A library of regular expressions:
Arguments:
name
The name of the method, used to identify and referencing it, must be a valid javascript identifier
method
The actual method implementation, returning true if an element is valid. First argument: Current value. Second argument: Validated element. Third argument: Parameters.
message(Optional),
The default message to display for this method. Can be a function created by jQuery.validator.format(value). When undefined, an already existing message is used (handy for localization), otherwise the field-specific messages have to be defined.