473,513 Members | 2,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

javascript for multiple email id's separated by ","

pradeepjain
563 Contributor
how to write javascript or is there any javascript fot validating multiple email id's ....ex xx@abc.com,yy@bbc.com


Thanks,
Pradeep
Jan 4 '08 #1
15 4842
gits
5,390 Recognized Expert Moderator Expert
hi ...

what should the validation do? ... post the code you have so far ...

kind regards
Jan 4 '08 #2
pradeepjain
563 Contributor
This is the script i am using for validation of single email id

[HTML]<script language = "Javascript">
/**
* DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
*/

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")
return false
}

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

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

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

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

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

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

return true
}

function ValidateForm(){
var emailID=document.frmSample.txtEmail

if ((emailID.value==null)||(emailID.value=="")){
alert("Please Enter your Email ID")
emailID.focus()
return false
}
if (echeck(emailID.value)==false){
emailID.value=""
emailID.focus()
return false
}
return true
}
</script>[/HTML]
Aug 6 '08 #3
gits
5,390 Recognized Expert Moderator Expert
you just need to split() the string with the comma-seperated list of email-addresses and use your function for every resulting array element ...:

Expand|Select|Wrap|Line Numbers
  1. var s = 'foo,bar';
  2. var a = s.split(',');
  3.  
  4. // -> a stores now: ['foo', 'bar']
kind regards
Aug 6 '08 #4
pradeepjain
563 Contributor
i am still learning javascripts...can u plzz show a small example of wht u explained
Aug 6 '08 #5
RamananKalirajan
608 Contributor
hi Pradeep, I give u a example. this will be useful for you.

[HTML]<html>
<head>
<script language="javascript">
function splitThis()
{
var names = new Array();
var input = document.getElementById('myText').value;
names=input.split(";");
for(i=0;i<names.length;i++)
alert("Names["+i+"] is "+names[i]);
}
</script>
</head>
Enter the name with ";" inbetween them: &nbsp;&nbsp;&nbsp;<input type="text" id="myText">
<br/>
<input type="button" value="Split Names" onclick="splitThis()">
</html>[/HTML]

In the place of alert you use the code to validate the emails

Regards
Ramanan Kalirajan
Aug 6 '08 #6
gits
5,390 Recognized Expert Moderator Expert
:) the exampe is right above in my previous post ... just call a function with the comma-seperated string as its input ... after the split just loop over the resuting array and call you validation for every emai-address:

Expand|Select|Wrap|Line Numbers
  1. function check_all(c_s_list) {
  2.     var arr = c_s_list.split(',');
  3.  
  4.     for (var i = 0, l = arr.length; i < l; i++) {
  5.         var adr = arr[i];
  6.  
  7.         // your validation here - may be you need some
  8.         // adaptions to handle the errors for every address
  9.         echeck(adr);
  10.     }
  11. }
  12.  
kind regards
Aug 6 '08 #7
pradeepjain
563 Contributor
ok thanks its working great now....hey i hve another problem....i need to validate like

pradeep jain:pradeep@bac.com,pradeep new:new@abc.com


is there a way to do it....
Aug 6 '08 #8
gits
5,390 Recognized Expert Moderator Expert
could you please explain in more detail: what is to validate?
Aug 6 '08 #9
RamananKalirajan
608 Contributor
ok thanks its working great now....hey i hve another problem....i need to validate like

pradeep jain:pradeep@bac.com,pradeep new:new@abc.com


is there a way to do it....
Hi Dude, whether pradeep jain & pradeep new are the first name and last name of the person who is having that mail id. You want to validate only the mail id not the name. If thats the case: have two arrays

ex: code

[HTML] var myArray1 = new Array();
var myArray2 = new Array();
var input = document.getElementById('textVal').value; //This has the pradeep jain:pradeep@bac.com,pradeep new:new@abc.com
myArray1 = input.split(",");
for(i=0;i<myArray1.length;i++)
{
myArray2 = myArray1[i].split(":")
// myArray2[0] ----> contains the Name
// myArray2[1] -----> contains the Id to be validates;
validate(myArray2[1]);
}[/HTML]

This is the way u can do it. If u have doubts post back it. I will try to help u out.

Regards
Ramanan kalirajan

}
Aug 6 '08 #10
pradeepjain
563 Contributor
Yes i used wht u have given ..its working but when user enters as
abc@abc.com,abc@bbc.com or
abx@abc.com

it doesnot work....i think i need to check if , is there ans split na.....how to do this....
Aug 7 '08 #11
pradeepjain
563 Contributor
the user might enter as
name:name@abc.com,nam1:name1@abc.com or
name@abc.com,name1@abc.com or
name:name@abc.com,name1@abc.com or
name@abc.com


this is the problem
Aug 7 '08 #12
RamananKalirajan
608 Contributor
the user might enter as
name:name@abc.com,nam1:name1@abc.com or
name@abc.com,name1@abc.com or
name:name@abc.com,name1@abc.com or
name@abc.com


this is the problem
See you have to maintain standards inprder top insist the user that this is my scope and this is my limitation or you have to use two logic and check before validating if the user has given the name then logic1 if the user name not given then logic2 you have to go by that. I would choose the first one rather than writing n no. of logics and complicating your code. Any further clarification post ur doubts

Regards
Ramanan Kalirajan
Aug 7 '08 #13
gits
5,390 Recognized Expert Moderator Expert
basicly an email-validation needs to check 3 things:

1. check for the @-character in every possible address
2. some domain-name check
3. some check for a valid name

there for you just need 3 steps:

1. split the user-input at the seperator(s) he might use -> result is an array with potential email-addresses

2. for every element split at the @ ... if you get 2 elements check 1. is ok ... now goto 3

3. check the first and second elements now - the first is the name-check and the second the domain check ...

alternativly you could use a regex to check everything in step 2 together ...

kind regards
Aug 7 '08 #14
pradeepjain
563 Contributor
See you have to maintain standards inprder top insist the user that this is my scope and this is my limitation or you have to use two logic and check before validating if the user has given the name then logic1 if the user name not given then logic2 you have to go by that. I would choose the first one rather than writing n no. of logics and complicating your code. Any further clarification post ur doubts

Regards
Ramanan Kalirajan

ok .....so u mean to say 2 email ids seperated by a " , " is best for validation and security rite....can u please tell me how to check weather a " , " is there in string or not so that i can use the logic...
Aug 7 '08 #15
RamananKalirajan
608 Contributor
ok .....so u mean to say 2 email ids seperated by a " , " is best for validation and security rite....can u please tell me how to check weather a " , " is there in string or not so that i can use the logic...

Consider your string is input. just use the following code

[HTML] if(input.indexOf(",")<0)
{your logic; }[/HTML]

This condition will return -1 if it doesn't finds any comma over there in your string. Use this logic.

Regards
Ramanan Kalirajan
Aug 7 '08 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

32
3348
by: Will Hartung | last post by:
Can someone clarify that multiple classes in the "class" attribute are ok and "legal" and not some fluke? So, I can do: ..pink {color: pink} ..bold {font-weight: bold} ..medium {font-size:...
1
5263
by: cemcat | last post by:
Hello, We have an ASP.NET 2.0 (C#) web form that contains a textbox for users to enter multiple e-mail addresses separated by semicolons. We need to validate that each individual e-mail address...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7161
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5686
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3234
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1596
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.