Validations  page     

plugin: jquery/model/validations
download: Validations
test: qunit.html

In many apps, it's important to validate data before sending it to the server. The jquery/model/validations plugin provides validations on models.

Example

To use validations, you need to call a validate method on the Model class. The best place to do this is in a Class's init function.

$.Model.extend("Contact",{
    init : function(){
        // validates that birthday is in the future
        this.validate("birthday",function(){
            if(this.birthday > new Date){
                return "your birthday needs to be in the past"
            }
        })
    }
},{});

Demo

Click a person's name to update their birthday. If you put the date in the future, say the year 2525, it will report back an error.

© Jupiter IT - JavaScriptMVC Training and Support