Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 date validation controls

Author  Topic 

susan_151615
Yak Posting Veteran

99 Posts

Posted - 2008-10-17 : 03:52:21
hi the u ser have to enter the date only in mm/dd/yyyy format for that i have written the validation control like this
its not hellping me
my coding is in vb.net can anyone help me in sorting this out

<asp:regularexpressionvalidator id="regExpDate" runat="server" Display="Dynamic" EnableClientScript="False" ControlToValidate="txtSelect"
ErrorMessage="It is not a valid date.Format is MMDDYY" ValidationExpression="^\d{2}[\/-]\d{2}[\/-]\d{2,4}$"></asp:regularexpressionvalidator></TD>

susan

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-10-20 : 03:25:29
duplicate
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=112758

So what is the error ?
Go to Top of Page

susan_151615
Yak Posting Veteran

99 Posts

Posted - 2008-10-20 : 04:40:33
no error is coming the validation is not working and i dono where i have gone wrong

susan
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-10-20 : 05:18:05
paste your code here
Go to Top of Page

susan_151615
Yak Posting Veteran

99 Posts

Posted - 2008-10-20 : 05:28:26
<asp:regularexpressionvalidator id="regExpDate" runat="server" Display="Dynamic" EnableClientScript="False" ControlToValidate="txtSelect"
ErrorMessage="It is not a valid date.Format is MMDDYY" ValidationExpression="^\d{2}[\/-]\d{2}[\/-]\d{2,4}$"></asp:regularexpressionvalidator>

susan
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-10-20 : 05:50:40
Your code that has the control txtSelect and the variable that catchs and holds the postback values
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-10-20 : 09:05:45
Don't use a regular expression validator, you are re-inventing the wheel.

You can use a Calendar Control to let the user pick a date from a calendar, or you can use a CompareValidator with Type="Date" and Operator="DataTypeCheck".


- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

susan_151615
Yak Posting Veteran

99 Posts

Posted - 2008-10-21 : 00:31:56
ok thank u smith i will try it out and check out and say

susan
Go to Top of Page

Ohmslaw
Starting Member

11 Posts

Posted - 2008-11-13 : 10:42:02
This is the validation expression I use for short dates:
\d{1,2}[/-]\d{1,2}[/-]((\d{4})|(\d{2}))

I use ((\d{4})|(\d{2})) to allow 4 or 2 numbers /d{2,4} will allow 2-4. I also found I had to use the greater number first when using | {or} later in the expression or it will fail.

Ohms...
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-11-13 : 11:08:32
That regular expression happily accepts 67/42/23 as a valid date ....

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

Ohmslaw
Starting Member

11 Posts

Posted - 2008-11-13 : 12:01:07
This control is only to validate syntax, but this expression can cut down on bad dates.
(([1][012])|([123456789]))[-/](([0123]\d{1})|(\d{1}))[-/](([123]\d{3})|(\d{2}))

You will have to validate Date through Datetime object as you posted to verify accual date.

Ohms...
Go to Top of Page
   

- Advertisement -