I have done a lot of server side form validation but until now, the only client side form validation I have done is to check for null/blank entries (e.g., if (value==''||value==null) ). I am now checking for user-entered vulgarities and have found success checking for these (incorporated into one variable - vulgarcheck) using javascript as follows:
<script language="javascript" type="text/javascript"> function CheckUserForm() { var usersuggestion=document.forms['UserForm']['userinput'].value; var vulgarcheck = /badword1|badword2|badword3|etc/gi; var vulgarcompare = usersuggestion.match(vulgarcheck); if (usersuggestion==''||usersuggestion==null) { alert('To make a suggestion, please enter text into the textbox'); return false; } else if (vulgarcompare!=null) { alert('The text you entered contains some vulgar language. Please try again!'); return false; } else { return true; } } </script>
Since I am new to javascript form validation more complex than a check for a null/blank-entry, I was hoping someone could tell me if my method has any oversight that I am not aware of. That is, are there potential problems with this method that I am missing? Thanks for your help!