HTML5 TextArea Validation with jQuery to disallow certain words

Posted by Baljeet Singh |20 Sep 14 | 0 comments

HTML5 TextArea Validation with jQuery to disallow certain words

 

In this tutorial i will show to how to validate html5 textarea with jQuery. Here i will be focusing on how to restrict some words to be typed in to the textarea. If these words are found then the form will not submit.

Reminder: Those of you who don’t know, html5 pattern attribute doesn’t work on textarea.

Create two files index.html & script.js as shown below.

index.html

 script.js

Here in script.js, when the document is ready & submit button is clicked jQuery checks to see the index of www & http in the textarea input string. If the words are found then form is not submitted else the form is submitted.

Note: You may also try using .match() jQuery function, which works similar to html5 pattern.

Print Friendly