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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -