Created
May 22, 2019 11:33
-
-
Save 0632347878/ea10617d4c8b7084fefeb7f591b7e0b8 to your computer and use it in GitHub Desktop.
validate add custom method
This file contains 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
$('.sme-form__form').validate({ | |
rules: { | |
phone: { | |
required: true, | |
regex : /\+38\(0(50|63|66|67|68|73|91|92|93|94|95|96|97|98|99)\)-\d{3}(-\d{2})(-\d{2})/ | |
}, | |
}); | |
$.validator.addMethod( | |
"regex", | |
function( value, element, regexp ) { | |
console.log(value); | |
if (regexp.constructor != RegExp) | |
regexp = new RegExp(regexp); | |
else if (regexp.global) | |
regexp.lastIndex = 0; | |
return this.optional(element) || regexp.test(value); | |
}, "Please specify a valid phone number" | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment