473,406 Members | 2,633 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,406 software developers and data experts.

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

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
4 1959
"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
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Wayno | last post by:
My php logs are coming up empty. I have done all I can think of, and all that made sense to me. Can someone take a look at my php.ini please and tell me what you think may be the problem. I...
3
by: tornado | last post by:
Hi all, I am pretty new to PHP. I was reading PHP manual and trying out the example from 2nd chapter (A simple Tutorial). When i try to print the variable as given in the example it returns...
21
by: AnnMarie | last post by:
<script language="JavaScript" type="text/javascript"> <!-- function validate(theForm) { var validity = true; // assume valid if(frmComments.name.value=='' && validity == true) { alert('Your...
1
by: Stephen Adam | last post by:
Hi there, I have written a custom validation control which checks to see of an input field is not empty and contains only numeric data. I was using a regular expression validation control but...
1
by: tshad | last post by:
Can you do Range Validation inside of an EditItemTemplate of the DataGrid? I have one set up as: ****************************************** <td> <asp:TextBox Columns="3" id="Weight"...
4
by: sanou | last post by:
Hi No doubt this question, or a similar version of it, has been asked before. But, I was looking around the forums and i couldn't find anything. I'm using VC++ to create a simple calculator...
11
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
7
by: tomlebold | last post by:
Are the following two validation the same: 1) IsNull(Me.ColumnName) and Me.ColumnName = "" 2) Me.ColumnName """ It would seem to be better to use: Me.ColumnName """
1
by: Fendi Baba | last post by:
I wrote a simple validation routine. I am trying to trigger validation on group of fields if an option on another radio button is selected. Sub ValidateAdd_ServerValidate(ByVal objSource As...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.