Click here to Skip to main content
12,763,337 members (33,911 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET Javascript
Hi friends,

I have a text box to Entered multiple email id's with comma/semicolon separator. I need to validate those emaild's using javascript. Because i have to sent email to those emailid's.

Could you please help me asap.

Thanks
Posted 10-Aug-12 0:26am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

first you replace all comma to semicolon and then use..
if str conatins you emailname string then..

var emails
str = str.replace(",",";");
emails = str.split(";")

now emails variable contains your all email ids...
  Permalink  
v3
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Hi try below

<asp:button id="btnSendInvite" runat="server" onclientclick="Javascript:return VerifyEmail();" text="Send Invite Now" />

<script type="text/javascript">

function VerifyEmail() {
var ids = document.getElementById('txtInvtMember').value


myArray = ids.split(',');
var i;
for (i = 0; i < myArray.length; i++) {
var emailID = trim(myArray[i]);
if (echeck(emailID) == false) { return false }
}
return true
}

function echeck(str) {

var at = "@"
var dot = "."
var lat = str.indexOf(at)
var lstr = str.length
var ldot = str.indexOf(dot)
if (str.indexOf(at) == -1) {
alert("Invalid E-mail ID: " + str)
return false
}

if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
alert("Invalid E-mail ID: " + str)
return false
}

if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
alert("Invalid E-mail ID: " + str)
return false
}

if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
alert("Invalid E-mail ID: " + str)
return false
}

if (str.indexOf(dot, (lat + 2)) == -1) {
alert("Invalid E-mail ID: " + str)
return false
}

if (str.indexOf(" ") != -1) {
alert("Invalid E-mail ID: " + str)
return false
}

return true
}

function trim(s) {
return rtrim(ltrim(s));
}

function ltrim(s) {
var l = 0;
while (l < s.length && s[l] == ' ')
{ l++; }
return s.substring(l, s.length);
}

function rtrim(s) {
var r = s.length - 1;
while (r > 0 && s[r] == ' ')
{ r -= 1; }
return s.substring(0, r + 1);
}

</script>
  Permalink  
v2

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

    Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 24 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100