Skip to content

Mortaza-Seydi/jquery-validation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Jquery Validation

simple form validation using jquery-validation

other components: select2, jBox and iCheck

Preview

form

with jquery-validation you can easily define rules

rules: {
    fname: "required",
    lname: "required",
    username: {
        required: true,
        username: true,
    },
    password: {
        required: true,
        minlength: 8,
    },
    c_password: {
        required: true,
        confirm_password: true
    },
    month: "required",

    day: {
        required: true,
        number: true,
        min: 1,
        max: 31
    },
    year: {
        required: true,
        number: true,
        min: 1800,
        max: 2020
    },
    gender: "required",
    agree: "required",
}

Custom validation methods

jquery.validator.addMethod("username", function (value, element) {

    return this.optional(element) || value == value.match(/^[a-zA-Z._]+$/);

}, "a-z, A-Z, ' . ' and ' _ ' only please");

jquery.validator.addMethod("confirm_password", function (value, element) {

    return this.optional(element) || value === jquery('#password').val();

}, "password does not match");