Click here to Skip to main content
Click here to Skip to main content

Validate multiple email id's using javascript

By , 23 Nov 2011
 
function validateEmail(field) {
    var regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,5}$/;
    return (regex.test(field)) ? true : false;
}
function validateMultipleEmailsCommaSeparated(emailcntl, seperator) {
    var value = emailcntl.value;
    if (value != '') {
        var result = value.split(seperator);
        for (var i = 0; i < result.length; i++) {
            if (result[i] != '') {
                if (!validateEmail(result[i])) {
                    emailcntl.focus();
                    alert('Please check, `' + result[i] + '` email addresses not valid!');
                    return false;
                }
            }
        }
    }
    return true;
}
 

Use javascript in text box lost focus event
Using semicolon separator
<asp:TextBox onblur="validateMultipleEmailsCommaSeparated(this,';');" ID="txtToEmail" Text="" runat="server" /> 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Ramanujam Shankar
Web Developer Mahindra Logisoft Business Solution Limited, Chenn
India India
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralReason for my vote of 5 good hint. PinmemberLeonardo Paneque23 Nov '11 - 17:42 
GeneralRe: Thanks a ton Buddy PinmemberRamanujam Shankar9 Feb '12 - 20:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 23 Nov 2011
Article Copyright 2011 by Ramanujam Shankar
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid