Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
I want to varify Mail address Valid or not,How to check MailAddress True or Valid,plz help me
Posted 10-Jan-13 21:25pm
Comments
Reza Alipour Fard at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

To validate a email id in textbox you can place this code in Validating event of textbox or in Leave event of textbox:
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[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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.[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

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
  Permalink  
Comments
Dheerendra Dwivedi at 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
hemantrautela at 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...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

Hi,
 
Pass emailid to this function you will get desired result.
 
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;
        }
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

Hi
 
I found this one
 
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
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,192
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 11 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100