Register
|
Articles
|
Questions
|
Projects
|
Asp.Net Tips
|
Free Magazines
|
Tutorials
|
Search
|
Write to us
|
Login
Search
Articles
Asp.Net 2.0
AJAX
ADO.Net
C#
Javascript
Books
Asp.Net 2.0
AJAX
ADO.NET
C#
JavaScript
MS SQL Server
SilverLight
VB.NET
XML
Web Service
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
How to validate multiple email addresses in a Textbox through JavaScript?
Posted by
Moderator1
on
5/27/2010 9:53:46 AM
2765
Views
This code snippet will help you to validate group of email addresses in a multi-line text
Box. In a multi-line textbox, one email address is entered in a line, which can be separated using the carriage return (\n) delimiter. The separated emails are passed to a JavaScript function that uses Internet Email Address Regular Expression for validation. You can set any delimiters to separate the email addresses, accordingly you need to change the function to separate it.
Place the below JavaScript code between the html <head></head> tags. The function fnValidation is the main function that is called from the button click event. This function separates the email address in the multi-line text box and passed one email address at a time to another JavaScript function fnValidateEmail to validate it. If email address is valid, the fnValidateEmail function will return true, otherwise it will return false.
<script>
function fnValidateEmail(EmailId)
{
var EmailRegExp = "\\w+([-+.\']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
var regex = new RegExp(EmailRegExp);
if (EmailId.match(regex))
return true;
else
return false;
}
function fnValidation()
{
var val = document.getElementById("TextBox1").value;
var newtext = val.split("\n");
for(var i=0 ;i < newtext.length; i++)
{
var validEmail = fnValidateEmail(newtext[i])
if (!validEmail)
{
alert("The list contains some Invalid Email ID.");
return false;
}
}
alert("All Email Address is Valid.");
}
</script>
Place a Textbox control and a Button control in the aspx page. Set the TextMode property of the TextBox as “MultiLine” and set the OnClientClick property of the button as “return fnValidation();”. The sample code is below.
<asp:TextBox ID="TextBox1" runat="server" Height="150px"
TextMode="MultiLine"></asp:TextBox>
<asp:Button ID="Button1" runat="server"
OnClientClick="return fnValidation();" Text="Validate Email" />
Post New Tips/Tricks
View all Tips/Tricks
Featured Resources:
Integrating Silverlight 4 with SharePoint 2010 - Free 42 Page Sample Chapter
A free sample chapter from Packt Enterprise's book: Microsoft Silverlight 4 and SharePoint 2010 Integration.
Easing the Migration to Microsoft SQL Server 2005
There are many business and technological reasons for making the move to SQL Server 2005 and SQL Server 2005 Enterprise Edition. In tandem with 64-bit computing platforms, SQL Server 2005 can boost performance by 30% in certain instances, deliver a better database management structure and bolster infrastructure security.
100% Free Subscription until Stock lost.
View complete list.
Sponsored by
Home
About us
Contact Us
Links
Advertise
Privacy Policy
Copyright ©
2012
. www.AspdotnetCodes.com. All rights reserved.