Newsgroup: it.comp.lang.javascript
Titolo: E-mail address validation Script

Anyone have everytime written script of some sort?
I like to know the grammar syntax to reimplement in my own script.
Bye.
-- 
-------------------------------------------------------------------------
The BitStreamer - 
thebits...@hotmail.com
Because living on the 'net is a stream of bits..
-------------------------------------------------------------------------




TheBitStreamer,
I did a basic one that only checks for the presence of an @ symbol.
url=prompt("Enter the email address ONLY.","");
if (url!=null && url!="") {
    while (url.indexOf("@")==-1) {
        alert("You have entered an invalid email address!");
        url=prompt("Enter the email address ONLY.","");
    }
    text=url;
}
And a second that only checks for the presence of @ and .
url=prompt("Enter the email address ONLY.","
na...@domain.com
");
if (url!=null && url!="") {
    a=url.indexOf("@");
    b=url.indexOf(".");
    while (url!=null&&a==-1&&b==-1) {
        alert("You have entered an invalid email address!");
        url=prompt("Enter the email address ONLY.","
na...@domain.com
");
    }
    text=url;
}
I am currently working on a more robust version by adapting another one
I'm working on to validate a URL, but it looks like more trouble than
it's worth (somebody somewhere has a better solution than I):
function go(url) {
    if (url!=null) {
      a1="http://";
      a2=url.indexOf("http://");
      // This _could_ get nasty...
      b=url.indexOf(".com");
      c=url.indexOf(".net");
      d=url.indexOf(".org");
      e=url.indexOf(".gov");
      f=url.indexOf(".com");
      // And even nastier...
      g=url.indexOf(".htm");
      h=url.indexOf(".html");
      i=url.indexOf(".shtml");
      j=url.indexOf(".asp");
      k=url.indexOf(".cgi");
      if ((!a2 && !b && !c && !d && !e && !f) && (!g && !h && !i && !j
&& !k) && url.substring(0,7)!=a1) {
        alert("You have entered an invalid URL!");
      }
    	else {
    	    alert("OK!");
            document.location.href=url;
    	}
    }
}
-- 
------------------------------------------
Kevin Brown
Design Staff Manager
MYERS INTERNET SERVICES
http://www.myer.com
(800) 693-7770

on Tue, 30 Jun 1998 17:46:52 GMT Kevin (
des...@myer.com
) wrote:
: TheBitStreamer wrote:
: > 
: > Anyone have everytime written script of some sort?
: > I like to know the grammar syntax to reimplement in my own script.
The only thing you can look for is @ and at least one dot after it.
: I am currently working on a more robust version by adapting another one
: I'm working on to validate a URL, but it looks like more trouble than
: it's worth (somebody somewhere has a better solution than I):
I can't see how is it more robust than anything. I've got .il as my
upper domain, so your script will say it's invalid. I don't like it :)
--
Dmitry Rubinstein.         <*>
Phone: 
+972-8-8647229
Home Page: 
http://www.wisdom.weizmann.ac.il/~dimrub
ICQ Id: 3816504

Here is a function I wrote to check email addresses.
Basically I check to see if they are syntacially correct.
If you find any bugs let me know. This function is used
to validate email addresses on numerous forms on my
companys website and we have had no reports of problems.
- David
function isEmailAddr(s) {
	if(isBlank(s))
		return false;
	var charBogus = "`~!#$%^&*()+={}[]\\|:;\"'<>,?/ ";
	var allValid = true;
	var atCount = 0;
	var i, j;
	for(i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		for(j = 0; j < charBogus.length; j++)
			if(c == charBogus.charAt(j)) {
				allValid = false;
				break;
			}
		if(allValid == false)
			return false;
		if(c == '@')
			atCount += 1;
	}
	return((atCount != 1) ? false : true);
}


Dmitry,
As I said, I'm working on it.  It doesn't currently work.  It is a "work
in progress".  I.e. unfinished, pre-beta.  
I posted it to show what it _might_ take to _really_ check if an e-mail
address were valid.  And as I also said, somebody somewhere has a better
solution than I.
Regards,
Kevin


 in progress".  I.e. unfinished, pre-beta.  
It will never work (at least in any usefull way) since I can always
come up with an address, that will look like a valid one, but it will
not be. Example:
som...@somewhere.com
OK, so it's syntactically valid. So?


 OK, so it's syntactically valid. So?
OK, I'll play with you...
Then lead by example and come up with a JavaScript Finger utility that
verifies the e-mail address exists prior to form post and handles the
exception when the user has finger disabled.  If so, it should then do a
whois on the domain and capture the results into a variable.  It should
append NOSPAM to the ReplyTo:, to avoid getting caught by any Spam
Address Trolling software, and you'll also want to include the
functionality to handle "Mail Delivery Subsystem <MAILER-DAEMON>
Subject: Returned mail: User unknown"
It needs to work on Netscape 2.02, 3.01, 3.03, 3.04, 4.01a, 4.03, 4.04,
4.05, and MSIE 3.01, 3.01a, 3.02, 3.03, 4.0 build [4.71.1712.6] and
[4.72.2106.8]  Let us know when you have it completed and tested.  
Then post the code.  Thanks!


Would like a piece of cake with that? :)
Kevin
