I’ve problem in adding a jQuery validation plugin method. I want to validate a field if it does not contain two consecutive underscores eg. __ or _ etc.
There’s something wrong with the matching pattern. I’m trying following:
jQuery.validator.addMethod("valid_word", function(value, element) {
return this.optional(element) || /[~__~]+$/i.test(value);
}, "Invalid word");
The above method will not accept a word if it does not include one or more underscores, so this is not what I want. I want it not to accept the word if it has consecutive underscores.
Thanks.
This method should work:
Replace your pattern with the above.
For help testing Regex, I recommend trying out The Regex Coach