In C#, I want to write a regular expression that will accept only years between 1900 and 2099.
I tried ^([1][9]\d\d|[2][0]\d\d)$
, but this does not work. Any ideas?
So i have in a class:
[NotNullValidator(MessageTemplate = "Anul nu poate sa lipseasca!")]
// [RangeValidator(1900, RangeBoundaryType.Inclusive, 2100, RangeBoundaryType.Inclusive, MessageTemplate = "Anul trebuie sa contina 4 caractere!")]
[RegexValidator(@"(19|20)\d{2}$", MessageTemplate = "Anul trebuie sa fie valid!", Ruleset = "validare_an")]
public int anStart
{
get;
set;
}
And in a test method:
[TestMethod()]
public void anStartTest()
{
AnUnivBO target = new AnUnivBO() { anStart = 2009 };
ValidationResults vr = Validation.Validate<AnUnivBO>(target, "validare_an");
Assert.IsTrue(vr.IsValid);
}
Why it fails?