Click to See Complete Forum and Search --> : Custom Email Validation
s01
January 31st, 2006, 08:20 AM
Hi,
I've a text box which gives comma separated emails. So for validating these emails i cannot use the Regular Expression validator. So please help me out with custom email validation code.
Thanks in advance!
Shuja Ali
January 31st, 2006, 08:29 AM
Hi,
I've a text box which gives comma separated emails. So for validating these emails i cannot use the Regular Expression validator. So please help me out with custom email validation code.
Thanks in advance!
Split the email addresses using the Split method (comma , as delimeter) and then validate each of them using the Refular Expression.
s01
February 1st, 2006, 04:09 AM
Ok, I can split the emails but how do i use a reg exp validator after that?
Shuja Ali
February 1st, 2006, 04:45 AM
here is one way of doing it Dim sEmails As String
'some email id's
sEmails = myId@mydomain.com,yourid@yourdomain.com,myid@yourdomain.com,yourid@mydomain.com,somejunk,validemail@validdomain.org
Dim sArray As String()
'split the email id's
sArray = sEmails.Split(",")
Dim lc As Integer
For lc = 0 To sArray.Length - 1
'check using the Regex
If Not System.Text.RegularExpressions.Regex.IsMatch(sArray(lc), "^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$") Then
System.Diagnostics.Debug.WriteLine(sArray(lc) & " emailID is not valid")
End If
Next
s01
February 1st, 2006, 11:56 PM
But how can i do this in C# or in javascript it would be better.
Shuja Ali
February 2nd, 2006, 02:16 AM
But how can i do this in C# or in javascript it would be better. In C# you can write the above code like this string sEmails;
string[] sArray;
sEmails = "put your comma separated emails here";
sArray = sEmails.Split(',');
for (int lc=0; lc < sArray.Length; lc ++)
{
if (! System.Text.RegularExpressions.Regex.IsMatch(sArray[lc], @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"))
{
System.Diagnostics.Debug.WriteLine(sArray[lc] + " emailID is not valid");
}
}Assign the emailID to sEmails in the above line. I was not able to post them because these emails IDs will get converted to mailto tag.
I am not so good at javascript so maybe someone else will post the code for Javascript.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.