java Script for Multiple email addresses validation


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: java Script for Multiple email addresses validation

  1. #1
    Join Date
    Jun 2006
    Posts
    2

    java Script for Multiple email addresses validation

    My form contains
    <tr>
    <td> MailAddresses</td>
    <td><textarea name="mailaddresses" rows="4" cols="40"></textarea></td> </tr>

    Here iam giving multiple email addresses separated by comma(,) in text area. Can any one provide java Script for Multiple email addresses validation to above scenario.......

    Thankyou very much in advance...

  2. #2
    Join Date
    Nov 2008
    Posts
    1

    try this function

    Code:
    function checkEmailForErrors (Form,Field) {
    var emailFilter2=/(([a-zA-Z0-9\-?\.?]+)@(([a-zA-Z0-9\-_]+\.)+)([a-z]
    {2,3})(\W?[,;]\W?(?!$))?)+$/i;
    var emailValue2=eval("document."+Form+"."+Field+".value");
    if (!(emailFilter2.test(emailValue2))) {
    return false;
    }else{
    return true;
    }
    }
    Last edited by Hack; 11-13-2008 at 08:39 AM. Reason: Added Code Tags

  3. #3
    Join Date
    Nov 2008
    Posts
    8
    HTML Code:
    <script type="text/javascript">
    function validate(email) {
       var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
       return reg.test(email);
    }
    
    function trim(str){
    	var	str = str.replace(/^\s\s*/,''),
    		ws = /\s/,
    		i = str.length;
    	while (ws.test(str.charAt(--i)));
    	return str.slice(0, i + 1);
    }
    
    function checkAll(){
    	var status = true;
    	var i = 0;
    	var emails = document.myform.mailaddresses.value.split(",");
    	for(i=0; i<emails.length; i++){
    		if(!validate(trim(emails[i]))){			
    			alert("Incorrect format: "+emails[i]);
    			status = false;
    			break;
    		}
    	}
    	if(status){
    		alert("List validated, "+i+" emails found");
    	}
    }
    </script>
    
    <form name="myform">
    	<textarea name="mailaddresses" rows="20" cols="100"></textarea>
    	<input type="button" onclick="checkAll();" value="check" />
    </form>
    this would do I suppose...

Similar Threads

  1. Java vs. .Net. A questionnaire
    By Basil in forum .NET
    Replies: 1
    Last Post: 05-13-2005, 07:46 AM
  2. .NET vs. Enterprise Java: Who's Got Better Security?
    By Glen Kunene in forum Talk to the Editors
    Replies: 17
    Last Post: 03-23-2002, 01:43 AM
  3. Web addresses in the outlook email
    By Gene in forum Enterprise
    Replies: 0
    Last Post: 12-18-2001, 10:09 AM
  4. Click Events in Java Script
    By Gary Smith in forum Web
    Replies: 0
    Last Post: 11-15-2001, 01:28 PM
  5. ALERT XP COULD DISABLE JAVA IN WEB BROWSERS AND EMAIL
    By Debbie Locker in forum Talk to the Editors
    Replies: 8
    Last Post: 07-24-2001, 08:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center