validate
can.Map.validations.static.validate
observe.validate(attrNames, [options,] validateProc)
Parameters
-
attrNames
{Array<String>}
Attribute name(s) to to validate
-
options
{Object}
OptionalOptions for the validations. Valid options include 'message' and 'testIf'.
-
validateProc
{function(value, attrName)}
Function used to validate each given attribute. Returns nothing if valid and an error message otherwise. Function is called in the instance context and takes the
value
andattrName
to validate.validate(attrNames, [options,] validateProc(value, attrName) )
validates each of the specified attributes with the givenvalidateProc
function. The function should return a value if there is an error. By default, the return value is the error message. Validations should be set in the Constructor's static init method.
The following example validates that a person's age is a number:
The error message can be overwritten with
options
message property: