CodeSmith Community
Your Code. Your Way. Faster!

Create a RegexIsMatch validation rule

Latest post 10-01-2007 7:29 AM by SleepyBoBos. 0 replies.
  • 10-01-2007 7:29 AM

    Create a RegexIsMatch validation rule

    To create a RegexIsMatch rule do the following

    1. Open the file [Insert your entity name here].cs in your Entities project

    2. Override the AddValidationRules method, if you have not already done so

    3. Add the rule as shown below using AddRule method

    The rule shown checks the EmailAddress property of the Entity to see that it is valid (I just copied the Regex from the standard ASP.NET Regex Validator control)

    const string VALID_EMAIL_ADDRESS = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";

    const string EMAIL_ADDRESS_COLUMN_NAME = "EmailAddress";

    protected override void AddValidationRules()

    {

             base.AddValidationRules();

             ValidationRules.AddRule(CommonRules.RegexIsMatch,new CommonRules.RegexRuleArgs(EMAIL_ADDRESS_COLUMN_NAME,VALID_EMAIL_ADDRESS));

    }

    Note : If you were adding this rule to the entity in a Processor you would instead add it as follows using the AddValidationRuleHandler method. The arguments to this method are the same as AddRule though.

    [your entity name here].AddValidationRuleHandler(CommonRules.RegexIsMatch,new CommonRules.RegexRuleArgs(EMAIL_ADDRESS_COLUMN_NAME,VALID_EMAIL_ADDRESS));
    • Post Points: 5
Page 1 of 1 (1 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems