473,587 Members | 2,568 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:CustomVali dator
ID="CustomValid atorTo"
runat="server"
ClientValidatio nFunction="vali dateTo"
ControlToValida te="TextBoxTo"
Display="Dynami c"
ErrorMessage="I nvalid e-mail address or addresses. E-mail address must
be in a standard format (na**@company.c om). Use a semicolon (;) with no
spaces to separate multiple e-mail addresses."
Text="*"
ToolTip="Invali d e-mail address or addresses. E-mail address must be in
a standard format (na**@company.c om). Use a semicolon (;) with no spaces to
separate multiple e-mail addresses."
ValidationGroup ="AllValidators "
OnServerValidat e="CustomValida torTo_ServerVal idate">
</asp:CustomValid ator>
<script type="text/javascript">
function validateTo(oSrc , args)
{
args.IsValid = false;

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

if (!formToValidat e)
{
formToValidate = document.aspnet Form;
}

var controlIndex;
var numberOfControl s = formToValidate. length;
var element;

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

if ((element.type == "text") &&
(element.id.las tIndexOf("TextB oxTo") > 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 5264
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******** ******@TK2MSFTN GP10.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:CustomVali dator
ID="CustomValid atorTo"
runat="server"
ClientValidatio nFunction="vali dateTo"
ControlToValida te="TextBoxTo"
Display="Dynami c"
ErrorMessage="I nvalid e-mail address or addresses. E-mail address must
be in a standard format (na**@company.c om). Use a semicolon (;) with no
spaces to separate multiple e-mail addresses."
Text="*"
ToolTip="Invali d e-mail address or addresses. E-mail address must be in
a standard format (na**@company.c om). Use a semicolon (;) with no spaces to
separate multiple e-mail addresses."
ValidationGroup ="AllValidators "
OnServerValidat e="CustomValida torTo_ServerVal idate">
</asp:CustomValid ator>
<script type="text/javascript">
function validateTo(oSrc , args)
{
args.IsValid = false;

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

if (!formToValidat e)
{
formToValidate = document.aspnet Form;
}

var controlIndex;
var numberOfControl s = formToValidate. length;
var element;

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

if ((element.type == "text") &&
(element.id.las tIndexOf("TextB oxTo") > 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
1135
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 complains that one of the individual documents root element is not defined. Is there a way to up the timeout value for validating through...
0
1272
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 document based on 1.xsd in "user area". 4 - TownHall.xsd - a description of a townhall-meant to be part of a document based on 2.xsd in "user area"....
1
2295
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 the xml fragment (to include default namespace xmlns='urn:xxx:yy' and any other namespace it may have), I still get the same error. ...
0
1546
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 control which had it's causes validation property set to true however if I tabbed on to this control the event wouldn't fire. So after playing around...
0
2427
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 (http://support.microsoft.com/kb/810852), but then I realized that the hotfix mentioned was in .Net v1.1, which I am using. I took the sample from that...
10
1732
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 with the intention of doing something only about the ones that failed validation. Unfortunately rather more of my pages were invalid than I hoped,...
0
942
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 strings that were found for display in a msgbox to let the user know that there were data errors found. This works great, however, sometimes a user...
2
1353
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
1142
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 <select name="txtservice" size="3" id="txtservice" multiple> <option value="1">Wrapping and Storage</option>
8
4118
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 prevailed it just is :) My problem is this im trying to validate the contents of a textbox (it has to be a normal textbox) and on a c#...
0
7918
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7843
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8206
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6621
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5713
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5392
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2353
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 we have to send another system
0
1185
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.