I am using:
[RegularExpression(@\"^(\"\"|\\[)?[a-zA-Z0-9\']{1,125}(\"\"|\\])?$\")]
to make sure each line of a multiline textbox is properl
It doesn't look like the RegularExpressionAttribute supports passing options, so here's one that allows it (compile checked but not tested):
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter,
AllowMultiple = false)]
public class RegExAttribute : ValidationAttribute
{
public string Pattern { get; set; }
public RegexOptions Options { get; set; }
public RegExAttribute(string pattern) : this(pattern, RegexOptions.None) { }
public RegExAttribute(string pattern, RegexOptions options)
{
Pattern = pattern;
Options = options;
}
public override bool IsValid(object value)
{
return Regex.IsMatch(value.ToString(), Pattern, Options);
}
}