Return to Snippet

Revision: 10307
at December 17, 2008 09:14 by charmcitycoder


Initial Code
function validateSpecialChars(myStringID)
{
     // declare which special chars to validate
     var illegalChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
     var strToSearch = document.getElementById(myStringID).value;

     for (var i = 0; i < strToSearch.length; i++) 
     {
  	if (illegalChars.indexOf(strToSearch.charAt(i)) != -1) 
        {
  	   alert ("Your search has one of the following special characters:\n" + iChars + "\nThese are not allowed.\nPlease remove them and try again.");
  	return false;
  	}
     }
}

Initial URL

                                

Initial Description
Always always always backup client side validation with server side validation! =D

Initial Title
Validate for Special Characters

Initial Tags
javascript, forms, validation

Initial Language
JavaScript