This project is read-only.

ValidateRegex

Description: Indicates a property must match a regular expression pattern.

Constructor(s):
  • public ValidateRegexAttribute(string pattern, string message)

Parameters:
  • pattern: The regular expression pattern used to validate.
  • message: The message to be used if validation fails.

Example Usage:
public class MyEntity : EvilBaseEntity
{
    private const string zipCodePattern = @"^[0-9]{5}([- /]?[0-9]{4})?$";

    [ValidateRegex(zipCodePattern, "Zip code does not match regular expression.")]
    public string ZipCode
    {
        // Omitted for brevity
    }
}


Valid Entity 1:
MyEntity entity = new MyEntity();
entity.ZipCode = "43210";

bool result = entity.IsValid();


Valid Entity 2:
MyEntity entity = new MyEntity();
entity.ZipCode = "43210-1234";

bool result = entity.IsValid();


Valid Entity 3:
MyEntity entity = new MyEntity();
entity.ZipCode = "432101234";

bool result = entity.IsValid();


Invalid Entity 1:
MyEntity entity = new MyEntity();
entity.ZipCode = "1a-*(&_@#$C";

bool result = entity.IsValid();


Invalid Entity 2:
MyEntity entity = new MyEntity();
entity.ZipCode = null;

bool result = entity.IsValid();


Invalid Entity 3:
MyEntity entity = new MyEntity();
entity.ZipCode = string.Empty;

bool result = entity.IsValid();

Last edited Dec 8, 2006 at 4:54 PM by Arcware, version 2

Comments

No comments yet.