Sometimes we need to check if a string contains any special charachter. Ex. name should not contains any special character.
Here is the code for it :
function IsSpecialChar(strString) // check for valid SpecialChar strings { var strValidChars = "<>@!#$%^&*()_+[]{}?:;|'\"\\,./~`-="; var strChar; var blnResult = true; if (strString.length == 0) return false; // test strString consists of valid characters listed above for (i = 0; i < strString.length && blnResult == true; i++) { strChar = strString.charAt(i); if (strValidChars.indexOf(strChar) == -1) { blnResult = false; } } return blnResult; }
Happy Learning......
No comments:
Post a Comment