Created
February 11, 2014 08:02
-
-
Save abrjagad/8930838 to your computer and use it in GitHub Desktop.
Common Jquery validation plugin Method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Global validation message | |
jQuery.extend(jQuery.validator.messages, { | |
required: "تعبئة هذا الحقل إجباري" | |
}); | |
// New Method like email; this one to check Emirates Id | |
jQuery.validator.addMethod('emiratesId', function (value) { | |
return /^\d{3}-?\d{4}-?\d{7}-?\d{1}$/.test(value); | |
}, 'Please enter a valid Emirates ID number'); | |
// common initialisation | |
$("#myRegisterForm").validate({ | |
groups: { | |
DateofBirth: "DOB MOB YOB" //grouping three input files; DOB MOB are attribute "name" | |
}, | |
rules: { | |
UserName: { | |
email: true //making something email field | |
}, | |
gender: { | |
required: true //making two fields | |
}, | |
Password: { | |
minlength: 6 | |
}, | |
ConfirmPassword: { | |
minlength: 6, | |
equalTo: "#Password" | |
}, | |
EmiratesID: { | |
emiratesId: true //custom method rule | |
}, | |
DOB: { | |
range: [1, 31] // date range | |
}, | |
MOB: { | |
range: [1, 12] | |
}, | |
YOB: { | |
range: [1930, 2014] | |
} | |
}, | |
messages: { | |
Password: { | |
minlength: "الرجاء إدخال 6 أحرف على الأقل." | |
}, | |
ConfirmPassword: { | |
equalTo: "يرجى إدخال نفس القيمة مرة أخرى." | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment