Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to block special characters in javascript

var iChars = "!@#$%^&*()+=-[]';,./{}|":<>?";

for (var i = 0; i < document.formname.fieldname.value.length; i++) {
    if (iChars.indexOf(document.formname.fieldname.value.charAt(i)) != -1) {
        alert ("Your username has special characters. 
These are not allowed.
 Please remove them and try again.");
        return false;
    }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #block #special #characters #javascript
ADD COMMENT
Topic
Name
7+6 =