With Jquery Validation for Bootstrap plugin, I have a form.
Now that I want to check a field that must contain a specific word. Like
Field have the word 'COMPLUSORY_WORD' in the string - return valid
Field don't have the word 'COMPLUSORY_WORD' in the string - return invalid
What additional method should I include in validation script?
You can try like this:
if (yourstring.indexOf("COMPLUSORY_WORD") >= 0)
You can also make your search case insensitive like this:
if (yourstring.toLowerCase().indexOf("COMPLUSORY_WORD") >= 0)
EDIT:
You can try to use it like this":
function checkWord(yourstring, compulsaryword)
{
return new RegExp( '\\b' + compulsaryword + '\\b', 'i').test(yourstring);
}
EDIT:
You can try this:
jQuery.validator.addMethod('COMPLUSORYWORDCHECK', function (value, element) {
return this.optional(element) || /^\bCOMPLUSORY_WORD\b$/.test(value);
}, "Compulsary word");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With