user2636787
user2636787

Reputation: 11

Accept Year Values in TextBox C#

I am a first-timer here. Not aware of the rules exactly.

My question is this: I have a TextBox and I want this TextBox to accept years only. The format of the text must be like 2012-2013

Any ideas?

Upvotes: 0

Views: 351

Answers (2)

Fizor
Fizor

Reputation: 1530

Welcome to Stack...

Here is a Regular expression that should work for you

^([0-9]{4})[./-]+([0-9]{4})$ //Results in 2012-2013 or 2012/2013

And as for adding it to your app, here is an article that could help you.

Upvotes: 1

Sajeetharan
Sajeetharan

Reputation: 222692

Put this regex in your code

^[12][0-9]{3}$

Upvotes: 0

Related Questions