Multiple e-mail id checking . ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jyaseen
    New Member
    • Feb 2010
    • 21

    Multiple e-mail id checking . ?

    if i insert multiple e-mail id in To textbox like below , how can i validate the email ids.
    <abidhudavi@gma il.com>, <naseehjasi@gma il.com>, "unaise hameed" <unaise2u@gmail .com>, "Yunus Mecheri" <YunusMecheri@g mail.com>,

    in google if we insert ids like above or comma separated , it will accept . anybody know the coding to validate this. in Javascript or PHP
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    Are you capturing this email id's in a text box?

    If yes, you can do by this way.

    HTML,
    Code:
     <input type="text" id="grpEmail" name="grpEmail" />
    JS,
    Code:
    var groupEmail = document.getElementById("grpEmail").value;
    if(groupEmail!=""&&groupEmail!=null)
    		{
    			//alert("Coming Inside");
    			var emailArr = groupEmail.split(",");
    			for(var i=0;i<emailArr.length;i++)
    			{
    				var result = return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(emailArr[i]);
    				if(result==false)
    				{
    					index=i;
    					emailFlag=false;
    					break;
    				}
    			}
    			if(emailFlag==false)
    			{
    				document.getElementById("MsgDiv").innerHTML="The Email Id "+emailArr[index]+" is Invalid. Please Change";
    				return false;
    			}
    
    		}
    Thanks and Regards
    Ramanan Kalirajan
    Last edited by RamananKalirajan; Feb 16 '10, 08:46 AM. Reason: Added Code Tags

    Comment

    • jyaseen
      New Member
      • Feb 2010
      • 21

      #3
      I try this code, with one textbox and submit button. butthere are mistakes in your code.

      1) var result = return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(emailArr[i]);
      in the above line it gives the Syntax error.

      2) if(emailFlag==f alse)
      the line emailFlag it says it is not declared.
      so can you clear this ?
      thank you for your replay

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        the return does not belong there.

        Comment

        • jyaseen
          New Member
          • Feb 2010
          • 21

          #5
          I removed return from code ,now it says unmatched ) in regular expression

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            can’t see any unmatched )

            PS. [a-zA-Z0-9_] = \w

            Comment

            • jyaseen
              New Member
              • Feb 2010
              • 21

              #7
              I did not understand how the below coding works
              /^[a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(emailArr[i])
              this line gives the error unmatched ) in regular expression

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                you didn’t copy the first (, that’s why.

                Comment

                • jyaseen
                  New Member
                  • Feb 2010
                  • 21

                  #9
                  Now it says emailFlag not defined ...

                  Comment

                  • jyaseen
                    New Member
                    • Feb 2010
                    • 21

                    #10
                    Now it is working, but my question is -> E-mail ids like below will accept in gmail or other email website. can I do like that.
                    abidhudavi@gmai l.com>, <naseehjasi@gma il.com>, "unaise hameed" <unaise2u@gmail .com>, "Yunus Mecheri" <YunusMecheri@g mail.com>

                    your code not validating if i put an email id like this . "Yunus Mecheri" <YunusMecheri@g mail.com> . I mean it should accept this email id format.
                    Is it Possible ...?

                    Comment

                    • Dormilich
                      Recognized Expert Expert
                      • Aug 2008
                      • 8694

                      #11
                      then you have to extend the RegExp …

                      Comment

                      • RamananKalirajan
                        Contributor
                        • Mar 2008
                        • 608

                        #12
                        Yep it is possible, you can do it...

                        Code:
                        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
                        <HTML>
                        <HEAD>
                        <TITLE> New Document </TITLE>
                        <META NAME="Generator" CONTENT="EditPlus">
                        <META NAME="Author" CONTENT="">
                        <META NAME="Keywords" CONTENT="">
                        <META NAME="Description" CONTENT="">
                        <script type="text/javascript">
                        	function passValue()
                        	{
                        		document.getElementById('emailInp').value='<naseehjasi@gmail.com>, "unaise hameed" <unaise2u@gmail.com>, "Yunus Mecheri" <YunusMecheri@gmail.com>';
                        		alert(document.getElementById('emailInp').value);
                        	}
                        
                        	function alertMailId()
                        	{
                        		var mailStr = document.getElementById('emailInp').value;
                        		var tempStr="";
                        
                        		for(var i=0;i<mailStr.length;i++)
                        		{
                        		   if(mailStr.charAt(i).indexOf("<")>-1)
                        		   {
                        				for(var j=(i+1);j<mailStr.length;j++)
                        				{
                        					if(mailStr.charAt(j).indexOf(">")<=-1)
                        						tempStr+=mailStr.charAt(j);
                        					else
                        						{
                        							tempStr+=";";
                        							i=j;
                        							break;
                        						}
                        				}
                        		   }
                        		}
                        
                        		alert(tempStr);
                        	}
                        </script>
                        </HEAD>
                        
                        <BODY onload="passValue();">
                        <input type="text" name="emailInp" id="emailInp" />
                        <input type="button" value="alertMailId()"  onclick="alertMailId()"/>
                        </BODY>
                        </HTML>
                        The value tempStr holds the mail id's alone now...

                        Thanks and Regards
                        Ramanan Kalirajan

                        Comment

                        • jyaseen
                          New Member
                          • Feb 2010
                          • 21

                          #13
                          good work , thank you I will check it and come back..

                          Comment

                          Working...