Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Testing broken rules
Message
De
26/02/2013 14:16:03
Tom Eby
Horizon Transport
Indiana, États-Unis
 
 
À
25/02/2013 08:24:37
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
01566055
Message ID:
01566969
Vues:
50
here's the code from my test

this is my test
        [Test]
        public void TestValidateEmail()
        {

            CustomerAddress customerAddressController = new CustomerAddress();

            string messageGood = customerAddressController.Rules.ValidateEmail("name@domain.com");
            Assert.IsNullOrEmpty(messageGood);

            string messageBad = customerAddressController.Rules.ValidateEmail("name@domain,com");
            Assert.IsNotNullOrEmpty(messageBad);
        }
this is the rule
       public string ValidateEmail(string email)
        {
            string msg = null;
            if (!Validate.Email(email))
            {
                this.EntityPropertyDisplayName = "Customer Email";

                msg = this.EntityPropertyDisplayName + " is not a valid email address!";

                AddErrorProviderWarning("Email", msg);
            }
            return msg;
        }
this is the Validate.Email method
	public static bool Email(string email)
        {
            string patternStrict = @"^(([^<>()[\]\\.,;:\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,}))$";

            Regex matcher = new Regex(patternStrict);
            bool isMatch = matcher.IsMatch(email);
            return isMatch;
        }
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform