Jquery Validation - Check word in String -
with jquery validation bootstrap plugin, have form.
now want check field must contain specific word. like
field have word 'complusory_word' in string - return valid
field don't have word 'complusory_word' in string - return invalid
what additional method should include in validation script?
you can try this:
if (yourstring.indexof("complusory_word") >= 0) you can make search case insensitive this:
if (yourstring.tolowercase().indexof("complusory_word") >= 0) edit:
you can try use 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"); 
Comments
Post a Comment