c# - Multiple Regex Data Annotation Validation -
i have string field in code first can contain 1 of 2 regular expressions:
([0-5]\d):([0-5]\d)\,(\d{2}) or (\d{3}),(\d{2}) how can combine them in 1 field? tried using custom validation. field validation true, if enter letters. can't find out i'm doing wrong.
[customresult] public string resultstring { get; set; } and
public class customresultattribute : validationattribute { public override bool isvalid(object value) { if (value == null) { return false; } // 00:00,00 if (regex.ismatch(value.tostring(), @"([0-5]\d):([0-5]\d)\,(\d{2})")) { return true; } // 000,00 if (regex.ismatch(value.tostring(), @"(\d{3}),(\d{2})")) { return true; } return false; } }
i think in case, can use or | in regex:
([0-5]\d):([0-5]\d)\,(\d{2})|(\d{3}),(\d{2}) put http://www.regexper.com/ see.
Comments
Post a Comment