Validating javascript code

If the attributes objects is an HTML/DOM/j Query element Even though none of the built in validators are async it is sometimes useful to have async validations.One example would be to check if a username is already used by asking the server.The project can be found on Git Hub where you can also find our issue tracker.

Any A type promise can be used, just override function success(attributes) function error(errors) var constraints = ; var attributes = ; // Will call the success function and log validate.async(attributes, constraints).then(success, error); // Will call the error function validate.async(, constraints).then(success, error); function Validation Errors(errors, options, attributes, constraints) Validation Errors.prototype = new Error(); // This isn't supported by the ES6 promises validate.async(, constraints, ) .then(success) .catch(Validation Errors, function(error) ) .catch(function(error) ); // Supporting another promise implementation (RSVP in this case) validate. Promise; Sometimes you only want to validate a single value against some constraints and using the normal validate function is quite verbose so there is a shorthand for this.

It does little more than proxying the call do the main validation function but with the value wrapped in an object and the options full Messages and format set to also has limited support for nested objects (objects within objects) using the dot notation.

The validation constraints can be declared in JSON and shared between clients and the server. One thing that is a bit unorthodox is that most validators will consider undefined values (,) valid values.

So for example adding a constraint of at least 6 characters will be like saying If the attribute is given it must be at least 6 characters.

If an is thrown from an async validator the argument passed to the rejection handler will be that error.