• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1671
  • Last Modified:

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}$
0
j_lainio
Asked:
j_lainio
  • 2
  • 2
  • 2
  • +1
2 Solutions
 
Jai STech ArchCommented:
it is better not to mingle DATE CHECKING with EMPTY string checking...
if it is a empty string checking then this regex will do..becos empty string is not a date....
0
 
ozoCommented:
An empty string does not match that regular expression, so what do you need to modify?
0
 
j_lainioAuthor Commented:
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}$" />
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
j_lainioAuthor Commented:
I have to mark my own findings as an answer for my problem... sorry! ;)
0
 
ZvonkoSystems architectCommented:
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.
======
0
 
Jai STech ArchCommented:
i think the points has to be split and the question must not be abandonned...
0
 
ZvonkoSystems architectCommented:
Thanks j! :)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now