Created
February 28, 2019 07:19
-
-
Save vikas-git/e460ee730fe4228e44826d392ae24248 to your computer and use it in GitHub Desktop.
Jquery Validate :: Additional validation for different type of value check.
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
$.validator.addMethod("emailFormat", | |
function (value, element) { | |
// return !/[0-9]*/.test(value); | |
return this.optional(element) || /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/.test(value); | |
}, | |
//'Please enter a valid email address.' | |
"Please enter a valid email" | |
); | |
$.validator.addMethod("blankSpace", | |
function (value, element) { | |
// return !/[0-9]*/.test(value); | |
if (value.trim() != value) | |
return false | |
else | |
return true; | |
}, | |
//'Please enter a valid email address.' | |
"Blank space are not allowed in start and end" | |
); | |
$.validator.addMethod('onecheck', function (value, ele) { | |
return $(".notification:checkbox:checked").length >= 1; | |
}, 'Please select atleast one checkbox') | |
jQuery.validator.addMethod("noSpace", function (value, element) { | |
return $.trim(value) != ""; | |
}, "Space are not allowed"); | |
$.validator.addMethod("usernameFormat", function (value, element) { | |
var regexp = '^(?=.*[0-9])([a-zA-Z0-9!@#$%^&*.]+){6,}$'; | |
var patt = new RegExp(regexp); | |
return this.optional(element) || patt.test(value); | |
}, "Username must be at least six characters and must include at least one number."); | |
$.validator.addMethod("passwordFormat", function (value, element) { | |
var regexp = '^(?=.*[0-9])([a-zA-Z0-9!@#$%^&*]+){8,}$'; | |
var patt = new RegExp(regexp); | |
return this.optional(element) || patt.test(value); | |
}, "Your password must be at least 8 characters long"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment