473,508 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validating Multiple E-mail Address - JavaScript & CustomValidator

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 entered is a valid e-mail
address format. We've added a CustomValidator to perform this validation.
We have the server-side validation working fine, but now we need to add some
client-side validation via JavaScript. We are having difficulties with
this.

Here's what we have so far:

<asp:TextBox ID="TextBoxTo" runat="server" ToolTip="To"></asp:TextBox>
<asp:CustomValidator
ID="CustomValidatorTo"
runat="server"
ClientValidationFunction="validateTo"
ControlToValidate="TextBoxTo"
Display="Dynamic"
ErrorMessage="Invalid e-mail address or addresses. E-mail address must
be in a standard format (na**@company.com). Use a semicolon (;) with no
spaces to separate multiple e-mail addresses."
Text="*"
ToolTip="Invalid e-mail address or addresses. E-mail address must be in
a standard format (na**@company.com). Use a semicolon (;) with no spaces to
separate multiple e-mail addresses."
ValidationGroup="AllValidators"
OnServerValidate="CustomValidatorTo_ServerValidate ">
</asp:CustomValidator>
<script type="text/javascript">
function validateTo(oSrc, args)
{
args.IsValid = false;

var formToValidate = document.forms['aspnetForm'];

if (!formToValidate)
{
formToValidate = document.aspnetForm;
}

var controlIndex;
var numberOfControls = formToValidate.length;
var element;

for (controlIndex = 0; controlIndex < numberOfControls;
controlIndex++)
{
element = formToValidate[controlIndex];

if ((element.type == "text") &&
(element.id.lastIndexOf("TextBoxTo") > 0))
{
// First trim any space and/or ; from the front or back of
the text entered in the textbox
// Split the text at every ; to get each individual e-mail
address
// Trim any space and/or ; from each individual e-mail
address
// Use a regular expression to validate each individual
e-mail address
}
}
}
</script>
Can anyone help us figure out the JavaScript code necessary to perform the
validation (see the commented line in the code above)?

Thanks!!!
Dec 19 '05 #1
1 5262
You might want to use regular expressions. A sample is here:
http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=22

"cemcat" <no****@company.com> wrote in message
news:uG**************@TK2MSFTNGP10.phx.gbl...
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 entered is a valid e-mail
address format. We've added a CustomValidator to perform this validation.
We have the server-side validation working fine, but now we need to add some
client-side validation via JavaScript. We are having difficulties with
this.

Here's what we have so far:

<asp:TextBox ID="TextBoxTo" runat="server" ToolTip="To"></asp:TextBox>
<asp:CustomValidator
ID="CustomValidatorTo"
runat="server"
ClientValidationFunction="validateTo"
ControlToValidate="TextBoxTo"
Display="Dynamic"
ErrorMessage="Invalid e-mail address or addresses. E-mail address must
be in a standard format (na**@company.com). Use a semicolon (;) with no
spaces to separate multiple e-mail addresses."
Text="*"
ToolTip="Invalid e-mail address or addresses. E-mail address must be in
a standard format (na**@company.com). Use a semicolon (;) with no spaces to
separate multiple e-mail addresses."
ValidationGroup="AllValidators"
OnServerValidate="CustomValidatorTo_ServerValidate ">
</asp:CustomValidator>
<script type="text/javascript">
function validateTo(oSrc, args)
{
args.IsValid = false;

var formToValidate = document.forms['aspnetForm'];

if (!formToValidate)
{
formToValidate = document.aspnetForm;
}

var controlIndex;
var numberOfControls = formToValidate.length;
var element;

for (controlIndex = 0; controlIndex < numberOfControls;
controlIndex++)
{
element = formToValidate[controlIndex];

if ((element.type == "text") &&
(element.id.lastIndexOf("TextBoxTo") > 0))
{
// First trim any space and/or ; from the front or back of
the text entered in the textbox
// Split the text at every ; to get each individual e-mail
address
// Trim any space and/or ; from each individual e-mail
address
// Use a regular expression to validate each individual
e-mail address
}
}
}
</script>
Can anyone help us figure out the JavaScript code necessary to perform the
validation (see the commented line in the code above)?

Thanks!!!

Dec 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1132
by: Adam Smith | last post by:
Hello. I have a document schema which imports the schema of four other documents. The problem is that when validating a document in the multiple import scenario, I get a timeout and then it...
0
1268
by: Adam Smith | last post by:
Hello. I've got a total of 5 schemas. They are: 1 - 1.xsd - a description of a city 2 - 2.xsd - a description of a town 3 - CityHall.xsd - a description of a cityhall-meant to be part of a...
1
2291
by: Wallace | last post by:
Hi all, I have a problem on validating a xml fragment using a single namespace schema which spread across multiple schema files using include in the master schema file. No matter how I change...
0
1543
by: Joe | last post by:
Hi For a while now I have been finding postings of problems with the validating event not firing on controls properly. I too had this problem. The event would fire when clicking on another...
0
2424
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852...
10
1717
by: Eric Lindsay | last post by:
How are people are validating multiple web pages? I thought most of my pages were valid so as a first try I used curl -F uploaded_file=@index.htm\;type=text/html http://validator.w3.org/check...
0
937
by: Bryan | last post by:
Visual basic 2005, .net 2.0: I pass my form's collection of controls to a public sub in a module that loops through and checks for any ErrorProvider text. The sub returns all the ErrorProvider...
2
1346
by: aris1234 | last post by:
Hi All... for validation one form i know the code, but if multiple form im confused my case : I have multiple form and submit in my html code, this is sample html : <form> <select>
0
1136
by: gnawz | last post by:
i have a multiple drop down with five items.. If i select 2 or more items and post, only one item is posted to the db! How do I make it post all the fields I have selected? The HTML list ...
8
4108
by: Peted | last post by:
I have an amazing problem which i think i have no hope of solving Im working with a c# dot net module that is hosted by and runs under a delphi form envrioment. Dont ask me how this insanity has...
0
7410
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7067
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
5650
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
4729
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
3215
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
3201
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
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 ...
1
774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
440
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.