Lot of times, i have noticed that we can enter multiple email addresses in a texbox or label. But the challenging thing about such a facility is validating them. What i mean is making sure they are valid email address. Here is a cool snippet which lets us do the validation. There are number of ways we can do this. I will mention a couple of them over here.
Method 1: We can use a JavaScript and a Regex Expression.
function checkEmailValid (Form,Field)
{
var emailCheck==/^[A-Z0-9\._%-]+@[A-Z0-9\.-]+\.[A-Z]{2,4}(?:[,;][A-Z0-9\._%-]+@[A-Z0-9\.-]+\.[A-Z]{2,4})*$/i;
var emailvalue=eval("document."+Form+"."+Field+".value");
if (!(emailCheck.test(emailValue2))) {
return false;
}else{
return true;
}
Method 2; This is very simple, I am using Asp.net 2.0 and C#. We can use the Regular Expression Control like this.
ValidationExpression="^(\s*,?\s*[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})+\s*$" ErrorMessage="Please enter a valid email." />
Just thought would share this.......Any comments or Suggestion are welcome
Tags:
Share
You need to be a member of e - p e a k s to add comments!
Join this Ning Network