Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to varify Mail address Valid or not,How to check MailAddress True or Valid,plz help me
Posted
Comments
Reza Alipour Fard 11-Jan-13 3:21am    
Do you need to check structure of entered text as e-mail address?
Or you need validate the entered text as e-mail address?
Please give more information.

To validate a email id in textbox you can place this code in Validating event of textbox or in Leave event of textbox:
ASP
System.Text.RegularExpressions.Regex rEMail = new System.Text.RegularExpressions.Regex(@"^[a-zA-Z][\w\.-]{2,28}[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$");

//txtmail is name/object of textbox
            if (txtmail.Text.Length > 0){

//rEMail is object of Regex class located in System.Text.RegularExpressions
                if (!rEMail.IsMatch(txtmail.Text))
                {
                    MessageBox.Show("E-Mail expected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtmail.SelectAll();
                    e.Cancel = true;
                }

The regex classes are located in the namespace System.Text.RegularExpressions. To make them available, place Imports System.Text.RegularExpressions at the start of your source code.

REgex provide immutable expression, and you can use System.Text.RegularExpressions to find a valuie in a richtextbox like in notepad or in any other application.
Found it here[^]

Check more details: here[^]
 
Share this answer
 
 
Share this answer
 
email address or any input field can be validated using the regular expression validator. If you are using ASP.NET then perhaps you can leverage the validation controls to do this:

Understanding ASP.NET Validation Techniques[^]

if you need to do it in Javascript then perhaps this could help you:

A Tiny Javascript Framework for Common Validation Scenarios.[^]
 
Share this answer
 
Here is some Confusion in your question.

1) if you want email format validation then you can easily get it as above solutions are there, using validation control.

2) If you want to check given email is exist or not then you have to verify it.
The process of verification is, you can send a email with a link or a one time password for this particular email for verification and when users come back using link or password then you can update the email validation.[for this you have to need some extra column in database, as emailvarify(true/false), one time password or link with one time id].


Thanks
Asp.Net/C#.Net Help[^]
Hemant Singh
 
Share this answer
 
Comments
Dheerendra Dwivedi 14-Jan-13 0:23am    
i want to write simply xyz@abc.com or abc@xyz.co.in or xyz@abc.in but not as asd@abc2321.in or abc@abc132121.com or other invalid
Hemant Singh Rautela 14-Jan-13 2:05am    
but as your examples abc@xyz123.com is not a invalid Email id it can ge exist.
eg. If my domain is sale99.com then my email can be info@sale99.com , so that it is not invalid...

I think you are not still clear about your scope/problem...
Hi,

Pass emailid to this function you will get desired result.

C#
function CheckEmail(email) {
            var emailpat = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
            var matchpat = email.match(emailpat);
            if (matchpat == null) {
                return false;
            }
            return true;
        }
 
Share this answer
 
Hi
I found this one

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using System.Web.UI;

namespace CompanyName.Library.Web.Controls
{
    [ToolboxData("<{0}:EmailValidator runat=server></{0}:EmailValidator>")]
    public class EmailValidator : BaseValidator
    {

        protected override bool EvaluateIsValid()
        {
            string val = this.GetControlValidationValue(this.ControlToValidate);
            string pattern = @"^[a-z][a-z|0-9|]*([_][a-z|0-9]+)*([.][a-z|0-9]+([_][a-z|0-9]+)*)?@[a-z][a-z|0-9|]*\.([a-z][a-z|0-9]*(\.[a-z][a-z|0-9]*)?)$";
            Match match = Regex.Match(val.Trim(), pattern, RegexOptions.IgnoreCase);

            if (match.Success)
                return true;
            else
                return false;
        }

    }
}


here: http://stackoverflow.com/questions/182542/email-address-validation-for-asp-net[^]

You can use it as Regex Validator as described on the mSDN page[^].

cheers,
Marco Alessandro Bertschi
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900