SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot shiftless's Avatar
    Join Date
    Mar 2005
    Posts
    137
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question email validation

    I have a javascript email validator that checks for the syntax of the email address. I need to modify it becuase it is not accepting emails with periods in the address that come after the @.

    this gets rejected for example:

    name@dio.minco.net

    here is what I'm using to validate:

    Code:
    var emailPat = /^([a-z0-9])(([\-.]|[_]+)?([a-z0-9]+))*(@)([a-z0-9])((([-]+)?([a-z0-9]+))?)*((.[a-z]{2,3})?(.[a-z]{2,6}))$/i;
    how can I modify this to accept addresses with the above format?

  2. #2
    SitePoint Addict jtrelfa's Avatar
    Join Date
    Oct 2004
    Location
    Troy, Mi
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Zealot Mr. Ram's Avatar
    Join Date
    Nov 2005
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)

    Lightbulb validation of e-mail-ID(s)

    Code:
    function validateTOMailID()	//	Validate TO, CC and BCC Mail-IDs
    {
    	
    		var flag = true;
    
    		if(document.form.toEMailID.value != "")				//	Validate TO Mail-ID
    		{
    
    				flag = validEMailIDs(document.form.toEMailID.value);
    		}
    
    		return flag;
    }
    
    function validEMailIDs(mailIDs)				//	Validate E-Mail-IDs
    {
    	var valid = true;
    
    	if(mailIDs.indexOf(";") != -1)			//	Check wheter Mail-IDs are separated by semicolons
    	{
    
    		alert("Mail-IDs should be separated by commas.");
    		valid = false;
    	}
    	else
    	{
    
    		var arrMailID = mailIDs.split(",");				//	split all Mail-IDs based on comma - Array of Mail-IDs
    
    		for(var j=0; j<arrMailID.length; j++)			//	check for each Mail-ID
    		{
    
    			// 1+@3+ [or x@x.x] is as close as we will test
    
    			var mailID = arrMailID[j];        
    			var mailID = trim(mailID);			//	Trim Each Mail-ID
    
    			if(mailID == "")
    			{
    
    				valid = false;
    				alert("Please remove the un-necessary comma operator(s).");
    				break;
    			}
    
    			var dot = mailID.lastIndexOf(".");				//	index of dot symbol
    			var at = mailID.indexOf("@");					//	index of at symbol
    			var dom = dot - at;									
    			var space = mailID.indexOf(" ");				//	index of space character
    			var lenMailID=mailID.length;
    
    			if( (lenMailID < 5) || (space != -1) || (at == -1) || (dot == -1) || (at < 1) || ( dom < 2) || 
    																  (dot == lenMailID-1) || (at == lenMailID-1) )
    			{
    
    				valid = false;
    				alert("The format of Mail-ID \"" + mailID + "\" is not correct.");
    				break;
    			}
    		}
    	}
    	return valid;
    }
    
    function trim(str)
    {
    
    	return str.replace( /^\s+/g,'').replace(/\s+$/g,'');
    }
    Last edited by Mr. Ram; Sep 24, 2007 at 05:32.

  4. #4
    Non-Member
    Join Date
    Aug 2007
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you very much, Mr. Ram


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •