Print Page | Close Window

Email Validation

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=492
Printed Date: 11-Jun-2026 at 4:35pm


Topic: Email Validation
Posted By: orcities
Subject: Email Validation
Date Posted: 12-Oct-2007 at 9:31am
When I run the below validation on an Email address it always fails and then I can not leave the box :

RegexVerifier v = new RegexVerifier(Descriptors.EmailAddress, true, NamedRegexPattern.Email);

v.AddTrigger(pEmailDescriptor);

v.ExecutionModes = VerifierExecutionModes.InstanceAndOnPresetTriggers;

return v;

 
To try a different method, and try and trace the error a bit further, I did the below validation and got the following validation error: ((IdeaBlade.Verification.VerifierResults)(verify)).Verifier is null

private static VerifierResult ValidEmailCondition(Email pEmail, TriggerContext triggerContext, VerifierContext verifierContext)

{

RegexVerifier v = new RegexVerifier(Descriptors.EmailAddress, true, NamedRegexPattern.Email);

      VerifierResult verify = v.Verify(pEmail.EmailAddress, triggerContext, verifierContext);

      return verify;

       

    }

private static Verifier EmailAddressVerifier(PropertyDescriptor pEmailDescriptor)

{

string description = "Email address must in a valid email format.";

      DelegateVerifier<Email> verifier = new DelegateVerifier<Email>(description, ValidEmailCondition);

      verifier.ExecutionModes = VerifierExecutionModes.InstanceAndOnPresetTriggers;

      verifier.AddTrigger(pEmailDescriptor);

      return verifier;

}

Why is any email address always failing?



Replies:
Posted By: eileenv
Date Posted: 12-Oct-2007 at 3:39pm
You shouldn't have to call AddTrigger since it is already added via the RegexVerifier constructor. Have you tried the following?
 
private static Verifier GetEmailAddressVerifier(PropertyDescriptor pEmailDescriptor)

    {

        RegexVerifier v = new RegexVerifier(pEmailDescriptor, true, NamedRegexPattern.Email);

        v.ExecutionModes = VerifierExecutionModes.OnPresetTriggers;

        return v;

       

    }



Posted By: orcities
Date Posted: 13-Oct-2007 at 10:22am
It still fails with that. Valid or not valid email. Then it doesn't let you out of the textbox.


Posted By: orcities
Date Posted: 15-Oct-2007 at 11:51am
What am I doing wrong?


Posted By: eileenv
Date Posted: 18-Oct-2007 at 3:51pm
Currently, the NamedRegexPattern.Email only allows uppercase letters. It has been updated to allow lowercase letters as well. This fix will be available in the Oct. 29 release.
 
Workarounds:
  1. In your app, enter an uppercase email, e.g. mailto:ANY@GMAIL.COM - mailto:ANY@GMAIL.COM. - ANY@GMAIL.COM .
  2. Override the email property to convert values to uppercase:

    public override string PersonalEmail {

      get { return base.PersonalEmail.ToUpper(); }

      set { base.PersonalEmail = value.ToUpper(); }

    }
  1. Create a new (corrected) email pattern and pass this into the RegexVerifier:

    #region Verification

 

    /// <summary>Get Verifiers.</summary>

    /// <param name="pVerifierProviderContext">Context in which these Verifiers are retrieved.</param>

    /// <returns>The verifiers.</returns>

    [VerifierProvider]

    public static IEnumerable<Verifier> GetVerifiers(Object pVerifierProviderContext) {

      List<Verifier> verifiers = new List<Verifier>();

 

      verifiers.Add(GetEmailAddressVerifier());

 

      return verifiers;

    }

 

    private static Verifier GetEmailAddressVerifier() {

      NamedRegexPattern emailPattern = new NamedRegexPattern("Email", @"\b[\w.%-]+@[\w.]+\.[a-zA-Z]{2,4}\b");

      RegexVerifier v = new RegexVerifier(Descriptors.PersonalEmail, true, emailPattern);

      v.ExecutionModes = VerifierExecutionModes.OnPresetTriggers;

      return v;

    }

    #endregion

Any of the above should work, but #3 is perhaps the cleanest, and will require no change on your part when the next release comes out.




Print Page | Close Window