Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Testing broken rules
Message
From
26/02/2013 14:16:03
Tom Eby
Horizon Transport
Indiana, United States
 
 
To
25/02/2013 08:24:37
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
01566055
Message ID:
01566969
Views:
51
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;
        }
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform