Skip to content

Instantly share code, notes, and snippets.

@abrjagad
Created February 11, 2014 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abrjagad/8930838 to your computer and use it in GitHub Desktop.
Save abrjagad/8930838 to your computer and use it in GitHub Desktop.
Common Jquery validation plugin Method
//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