Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

handling special charecters in email field  RSS feed

Chennarao Marvatu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Friends how are you..Hope you all fine.
Here my question is regarding not allowing the special charecters
in the email.I have taken the allowed charecters and not allowed charecters.
its working fine but i have to take only allowed charecters and other than
this charecters should not be allowed.So please help me out how to solve this by removing the notallowed charecters

function CheckValidity(textarea)
var key;
var keychar;
if (window.event)
key = window.event.keyCode;
else if (event)
key = event.which;
return true;

keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();
var allowedChars = "abcdefghijklmnopqrstuvwxyz1234567890@,_.-";
var notAllowedChars = "~`!#$%^&*()+=|\\\"\/';:?";

if((allowedChars.indexOf(keychar) greaterthan -1) || key == 13 ){

return ;
else {
var temp = textarea.value ;
for(i=0;i lessthan temp.length;i++){
var tempkeychar = temp.charAt(i);
if(notAllowedChars.indexOf(tempkeychar) greaterthan -1){
// alert("after charecter----"+notAllowedChars.indexOf(tempkeychar));
document.forms[0].email.value = temp.substr(0,i)+temp.substr(i+1,temp.length);
//alert("before charecter----"+temp.substr(0,i));
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!