I have a textbox in which the user will enter data in the following way.
e.g. 1.2-2012-2
But it could also be; 12.5-2010-4 (Emphasis on the first part)
My first approach was a MaskedTextBox but as the first part does not have a definite size, I can’t use that.
Now I want to validate the textbox. i.e. I will let the user enter what he/she wants to but in the end I want to know if he/she has entered it in the correct way.
e.g. If the user types a12.4/2012^14 (which is incorrect) I would know.
I have no idea how to convert this idea into code so please could someone guide me.
If there’s an alternative approach.
I have a textbox in which the user will enter data in the following
Share
You can use
TextChangedevent andRegexexpression:I have tested this code. It’s works. The only thing I don’t know your pattern exactly but above one should work.
If . is optional then use this pattern:
@"^(\d)+(\.\d)*-(\d){4}-\d$"