Link to home
Create AccountLog in
Avatar of j_lainio
j_lainioFlag for Finland

asked on

Datetime regExp which doesn't allow empty value

How should I modify this Datetime regular expression to check also that empty value is NOT legal (including whitespace chars)?

^([1-9]|0[1-9]|1[012])[- /.]([1-9]|0[1-9]|[12][0-9]|3[01])[- /.][0-9]{4}$
ASKER CERTIFIED SOLUTION
Avatar of Jai S
Jai S
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of j_lainio

ASKER

I fully understand your point and agree with it! My case is that i'm using Asp.Net RegularExpressionValidator control to validate user input. Input field must have value which means that empty value can not given. This control does validation with my regular expression but will pass empty value - which I don't want.

And actually I found a way (a bit stupid, but anyway) to handle problem with these asp.net controls. I will use 2 different controls to handle my validation like this:

Validate that value is NOT empty:
<asp:RequiredFieldValidator ControlToValidate="DateTimeTextBox" Text="Cannot be empty" runat="server" Display="Dynamic" />

Validate that value is in correct format:
<asp:RegularExpressionValidator ControlToValidate="DateTimeTextBox" Display="Dynamic" Text="Format is invalid..." runat="server" ValidationExpression="^([1-9]|0[1-9]|1[012])[- /.]([1-9]|0[1-9]|[12][0-9]|3[01])[- /.][0-9]{4}$" />
I have to mark my own findings as an answer for my problem... sorry! ;)
Sorry but you are here exchanging with other experts findings. And you cannot keep your points because you stated wrong your question and expected wizards can read your mind and your dot.Net environment. Both Experts answered absolutely correct your question so is the points split the only choice. But I am also sure that both Experts grant the points back as a gift to you ;-)

And I am also sure that both Experts would not argue with you for points because they are too polite, therefore I am jumping in to help you getting help from them in your next question with your saved points :)

Can you see it that way?

Here also an internet page stating the ASP.NET RegExp problem:
http://authors.aspalliance.com/chapters/0672320681/0672320681_CH03.aspx
=====
.. you'll quickly discover that you can submit the form without entering any text into the text box. The RegularExpressionValidator control does not require a value.
The only way to require a value is to combine RegularExpressionValidator with RequiredFieldValidator. Nothing prevents you from associating multiple Validator controls with the same control.
======
i think the points has to be split and the question must not be abandonned...
Thanks j! :)