473,394 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

regularExpressionValidator and dateTime

Ben
Hi,

i would like to find a validationexpression for a
regularexpresssionvalidator for DateTime from 1900 like thsi:
dd/mm/yyyy (european).

I couls find some at http://regexlib.com
but strange enough, all the validation i found there failed when typing a
year before 2000 (e.g. 1999)

Thanks
Ben
Jun 20 '07 #1
4 5293
Good evening Ben,

Use RangeValidator instead:

<asp:TextBox runat="server" ID="txtDate" />
<asp:RangeValidator Type="Date" runat="server" ID="rv"
ErrorMessage="Please enter a valid date greater than 01/01/1900"
EnableClientScript="true" ControlToValidate="txtDate"
MinimumValue="01/01/1900" MaximumValue="01/01/2999"
Display="Dynamic" CultureInvariantValues="false" />
<asp:RequiredFieldValidator runat="server" ID="rfv"
ErrorMessage="Please enter a date in the DD/MM/YYYY format"
ControlToValidate="txtDate" Display="Dynamic"
EnableClientScript="true" /><br />
<asp:Button runat="server" ID="btnSubmit" Text="Submit" />

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
System.Threading.Thread.CurrentThread.CurrentCultu re =
new System.Globalization.CultureInfo("en-gb");
}
</script>

Hope this helps
--
Milosz
"Ben" wrote:
Hi,

i would like to find a validationexpression for a
regularexpresssionvalidator for DateTime from 1900 like thsi:
dd/mm/yyyy (european).

I couls find some at http://regexlib.com
but strange enough, all the validation i found there failed when typing a
year before 2000 (e.g. 1999)

Thanks
Ben
Jun 20 '07 #2
Hello,

If the format that you need is exactly dd/mm/yyyy and the year greater
than 1900, you can use the following RegEx:
^\d\d/\d\d/(19|2\d)\d\d$

there you say, two digits for days, two digits for month, and 19XX or
2XXX for year (^and $ is to say I want exactly this full string, no
substrings patterns).

You can find a good free tool to check regular expression:

http://www.codeproject.com/dotnet/expresso.asp

HTH
Braulio

--
/// ------------------------------
/// Braulio DÃ*ez
///
/// http://www.tipsdotnet.com
/// ------------------------------


"Ben" wrote:
Hi,

i would like to find a validationexpression for a
regularexpresssionvalidator for DateTime from 1900 like thsi:
dd/mm/yyyy (european).

I couls find some at http://regexlib.com
but strange enough, all the validation i found there failed when typing a
year before 2000 (e.g. 1999)

Thanks
Ben
Jun 21 '07 #3
Ben
Thanks to both of you

"Braulio Diez" <br**************@yahoo.esschreef in bericht
news:D9**********************************@microsof t.com...
Hello,

If the format that you need is exactly dd/mm/yyyy and the year greater
than 1900, you can use the following RegEx:
^\d\d/\d\d/(19|2\d)\d\d$

there you say, two digits for days, two digits for month, and 19XX or
2XXX for year (^and $ is to say I want exactly this full string, no
substrings patterns).

You can find a good free tool to check regular expression:

http://www.codeproject.com/dotnet/expresso.asp

HTH
Braulio

--
/// ------------------------------
/// Braulio Díez
///
/// http://www.tipsdotnet.com
/// ------------------------------


"Ben" wrote:
>Hi,

i would like to find a validationexpression for a
regularexpresssionvalidator for DateTime from 1900 like thsi:
dd/mm/yyyy (european).

I couls find some at http://regexlib.com
but strange enough, all the validation i found there failed when typing a
year before 2000 (e.g. 1999)

Thanks
Ben

Jun 21 '07 #4
Hi Braulio,

Unfortunatelly, regex you have given tests lexical validity only, whilst he
requires logical date validation as well (number of days in a month is not
fixed, leap years etc)

regards
--
Milosz
"Braulio Diez" wrote:
Hello,

If the format that you need is exactly dd/mm/yyyy and the year greater
than 1900, you can use the following RegEx:
^\d\d/\d\d/(19|2\d)\d\d$

there you say, two digits for days, two digits for month, and 19XX or
2XXX for year (^and $ is to say I want exactly this full string, no
substrings patterns).

You can find a good free tool to check regular expression:

http://www.codeproject.com/dotnet/expresso.asp

HTH
Braulio

--
/// ------------------------------
/// Braulio DÃ*ez
///
/// http://www.tipsdotnet.com
/// ------------------------------


"Ben" wrote:
Hi,

i would like to find a validationexpression for a
regularexpresssionvalidator for DateTime from 1900 like thsi:
dd/mm/yyyy (european).

I couls find some at http://regexlib.com
but strange enough, all the validation i found there failed when typing a
year before 2000 (e.g. 1999)

Thanks
Ben

Jun 21 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andy Eshtry | last post by:
I have a radio button list, a textbox representing SIN or EIN based on my radio button list selection so I put 2 regularexpressionvalidator to evaluate the value of textbox. EIN must be (for...
3
by: Ricardo Corsi P. Cesar | last post by:
Hi, i looking for example in asp.net (VB) to make the RegularExpressionValidator in runtime in my code behind. I found some similars codes, but nothing in VB.. thanks!
3
by: DC | last post by:
I have this snippet: <tr> <td align="left">E-mail</td> <td> <asp:TextBox id="txtEmail" runat="server" MaxLength="100"></asp:TextBox>&nbsp; <asp:RegularExpressionValidator id="revEmail"...
0
by: Matt Morris | last post by:
Hello: I have a RegularExpressionValidator control attached to a TextBox. I have the ValidationExpression property set to a very simple validation expression (\w+). The validation always fails...
3
by: tshad | last post by:
I have a RegularExpressionValidator that doesn't seem to work correctly if you don't enter anything. In the following, it works correctly if you have at least 1 character. If you just enter...
0
by: venkat Murthy | last post by:
Hi, I have 10 regularexpression validators in my datagrid. my datagrid looks like; first5controls | boundcolumn | next5controls. Regularexpressionvalidator for first five controls works...
1
by: franz | last post by:
does anybody tell me why it doesn't works?? in any case gg beame true thanks franz Dim y As RegularExpressionValidator = New RegularExpressionValidator y.ValidationExpression =...
1
by: John Yopp | last post by:
I'm trying to use a asp:RegularExpressionValidator to validate the strength of a password. When I test the regular expression with Regex.IsMatch, it works perfectly. However, when used within a...
4
by: =?Utf-8?B?Y3VyaW91cw==?= | last post by:
I am using a RegularExpressionValidator to validate a TextBox. I use "^?+(\.*)?$" to check for a real number. The control works fine as long as the user enters something in the TextBox; it does not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.