It's not a secret anymore!
The moose likes HTML, CSS and JavaScript and the fly likes handling special charecters in email field Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "handling special charecters in email field" Watch "handling special charecters in email field" New topic

handling special charecters in email field

Chennarao Marvatu
Ranch Hand

Joined: Aug 09, 2004
Posts: 32
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));

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: handling special charecters in email field
It's not a secret anymore!