Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript ASP>NET
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 9-Aug-12 23:26pm
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
0 Sergey Alexandrovich Kryukov 354
1 Richard MacCutchan 240
2 OriginalGriff 225
3 Jared Sanow 145
4 Vinay Mistry 133
0 Sergey Alexandrovich Kryukov 5,955
1 OriginalGriff 4,805
2 CPallini 2,473
3 Abhinav S 1,507
4 Richard MacCutchan 1,437


Advertise | Privacy | Mobile
Web04 | 2.8.140814.1 | Last Updated 24 Sep 2012
Copyright © CodeProject, 1999-2014
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