/ Published in: JavaScript

Always always always backup client side validation with server side validation! =D
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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; } } }
Comments
