Click here to Skip to main content
15,885,156 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

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

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

now emails variable contains your all email ids...
 
Share this answer
 
v3
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>
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900