By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,835 Members | 1,454 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,835 IT Pros & Developers. It's quick & easy.

Validation of empty, or range of values in a text box

P: n/a
Hi,

I want to validate a text box, The user can leave it blank, or fill it
in. If they fill it in then it must be a date within a certain range.

How can I achieve this?

Thank you very much
Nov 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Fraggle" <Fr************@yahoo.com> wrote in message
news:ce*************************@posting.google.co m...
Hi,

I want to validate a text box, The user can leave it blank, or fill it
in. If they fill it in then it must be a date within a certain range.

How can I achieve this?


I'd do that as a server side validation... you don't even need the validator
for that. Throw a label in the area you want the error message to appear.
Write a boolean function that returns true if the text box is blank, or if
not, parses with DateTime.Parse to a date within your range. Then call the
function from your submit button's event

R.
Nov 18 '05 #2

P: n/a
"Richard K Bethell" <so*****@spammingisevil.bad> wrote in message news:<OW*************@tk2msftngp13.phx.gbl>...
"Fraggle" <Fr************@yahoo.com> wrote in message
news:ce*************************@posting.google.co m...
Hi,

I want to validate a text box, The user can leave it blank, or fill it
in. If they fill it in then it must be a date within a certain range.

How can I achieve this?


I'd do that as a server side validation... you don't even need the validator
for that. Throw a label in the area you want the error message to appear.
Write a boolean function that returns true if the text box is blank, or if
not, parses with DateTime.Parse to a date within your range. Then call the
function from your submit button's event

R.


Thanks.

Maybe one day I will actually do something simple enough that uses the
more "advanced" features of the .net framework, rather than having to
custom write EVERYTHING!
Nov 18 '05 #3

P: n/a
Oh boy! That suggestion actually is much harder than using a validator.

Use the RangeValidator. It ignores blank fields automatically. It only
checks for errors when there is some text. Set Type=Date and your minimum
and maximum dates in the Minimum and Maximum properties.

Note that this will not report an error if the date entered is an illegal
format.
For that, use CompareValidator, Operator=DataTypeCheck, Type=Date.

Here are several ways to enhance your user interface:
1. You can combine the logic of several validators into one using the
MultiConditionValidator, part of my Professional Validation And More
product. (http://www.peterblum.com/vam/home.aspx) It includes 22 validators
and greatly expands what you can do with validators. You can learn about the
limitations of Microsofts validators here:
http://www.peterblum.com/vam/valmain.aspx to use as you design your site.

2. There are many really nice date textboxes with popup calendars available
from third parties. They are listed at the www.asp.net Control Gallery,
www.123aspx.com, and www.411asp.net. Mine is Peter's Date Package
(http://www.peterblum.com/datecontrols/home.aspx). It includes validators,
time entry, and stand-alone calendar that doesn't require post backs.

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"Fraggle" <Fr************@yahoo.com> wrote in message
news:ce**************************@posting.google.c om...
"Richard K Bethell" <so*****@spammingisevil.bad> wrote in message

news:<OW*************@tk2msftngp13.phx.gbl>...
"Fraggle" <Fr************@yahoo.com> wrote in message
news:ce*************************@posting.google.co m...
Hi,

I want to validate a text box, The user can leave it blank, or fill it
in. If they fill it in then it must be a date within a certain range.

How can I achieve this?


I'd do that as a server side validation... you don't even need the validator for that. Throw a label in the area you want the error message to appear. Write a boolean function that returns true if the text box is blank, or if not, parses with DateTime.Parse to a date within your range. Then call the function from your submit button's event

R.


Thanks.

Maybe one day I will actually do something simple enough that uses the
more "advanced" features of the .net framework, rather than having to
custom write EVERYTHING!

Nov 18 '05 #4

P: n/a
I would have to agree that using a validator would be a much simpler way to go. This is exactly what they were designed for.

Chris
--------------------
From: "Peter Blum" <PL****@Blum.info>
References: <ce*************************@posting.google.com> <OW*************@tk2msftngp13.phx.gbl> <ce**************************@posting.google.com >Subject: Re: Validation of empty, or range of values in a text box
Date: Thu, 8 Jul 2004 12:08:51 -0400
Lines: 62
Organization: www.PeterBlum.com
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
Message-ID: <uZ**************@tk2msftngp13.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: h0008021f4212.ne.client2.attbi.com 66.30.93.100
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:245575
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

Oh boy! That suggestion actually is much harder than using a validator.

Use the RangeValidator. It ignores blank fields automatically. It only
checks for errors when there is some text. Set Type=Date and your minimum
and maximum dates in the Minimum and Maximum properties.

Note that this will not report an error if the date entered is an illegal
format.
For that, use CompareValidator, Operator=DataTypeCheck, Type=Date.

Here are several ways to enhance your user interface:
1. You can combine the logic of several validators into one using the
MultiConditionValidator, part of my Professional Validation And More
product. (http://www.peterblum.com/vam/home.aspx) It includes 22 validators
and greatly expands what you can do with validators. You can learn about the
limitations of Microsofts validators here:
http://www.peterblum.com/vam/valmain.aspx to use as you design your site.

2. There are many really nice date textboxes with popup calendars available
from third parties. They are listed at the www.asp.net Control Gallery,
www.123aspx.com, and www.411asp.net. Mine is Peter's Date Package
(http://www.peterblum.com/datecontrols/home.aspx). It includes validators,
time entry, and stand-alone calendar that doesn't require post backs.

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"Fraggle" <Fr************@yahoo.com> wrote in message
news:ce**************************@posting.google. com...
"Richard K Bethell" <so*****@spammingisevil.bad> wrote in message

news:<OW*************@tk2msftngp13.phx.gbl>...
> "Fraggle" <Fr************@yahoo.com> wrote in message
> news:ce*************************@posting.google.co m...
> > Hi,
> >
> > I want to validate a text box, The user can leave it blank, or fill it
> > in. If they fill it in then it must be a date within a certain range.
> >
> > How can I achieve this?
>
> I'd do that as a server side validation... you don't even need thevalidator > for that. Throw a label in the area you want the error message toappear. > Write a boolean function that returns true if the text box is blank, orif > not, parses with DateTime.Parse to a date within your range. Then callthe > function from your submit button's event
>
> R.


Thanks.

Maybe one day I will actually do something simple enough that uses the
more "advanced" features of the .net framework, rather than having to
custom write EVERYTHING!


Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.