473,657 Members | 2,517 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1969
"Fraggle" <Fr************ @yahoo.com> wrote in message
news:ce******** *************** **@posting.goog le.com...
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*****@spammi ngisevil.bad> wrote in message news:<OW******* ******@tk2msftn gp13.phx.gbl>.. .
"Fraggle" <Fr************ @yahoo.com> wrote in message
news:ce******** *************** **@posting.goog le.com...
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 CompareValidato r, Operator=DataTy peCheck, Type=Date.

Here are several ways to enhance your user interface:
1. You can combine the logic of several validators into one using the
MultiConditionV alidator, 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****@PeterBlu m.com
Creator of "Profession al Validation And More" at
http://www.peterblum.com/vam/home.aspx

"Fraggle" <Fr************ @yahoo.com> wrote in message
news:ce******** *************** ***@posting.goo gle.com...
"Richard K Bethell" <so*****@spammi ngisevil.bad> wrote in message

news:<OW******* ******@tk2msftn gp13.phx.gbl>.. .
"Fraggle" <Fr************ @yahoo.com> wrote in message
news:ce******** *************** **@posting.goog le.com...
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.in fo>
References: <ce************ *************@p osting.google.c om> <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.publi c.dotnet.framew ork.aspnet
NNTP-Posting-Host: h0008021f4212.n e.client2.attbi .com 66.30.93.100
Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!tk2 msftngp13.phx.g bl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.framew ork.aspnet:2455 75
X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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 CompareValidato r, Operator=DataTy peCheck, Type=Date.

Here are several ways to enhance your user interface:
1. You can combine the logic of several validators into one using the
MultiCondition Validator, 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****@PeterBlu m.com
Creator of "Profession al Validation And More" at
http://www.peterblum.com/vam/home.aspx

"Fraggle" <Fr************ @yahoo.com> wrote in message
news:ce******* *************** ****@posting.go ogle.com...
"Richard K Bethell" <so*****@spammi ngisevil.bad> wrote in message

news:<OW****** *******@tk2msft ngp13.phx.gbl>. ..
> "Fraggle" <Fr************ @yahoo.com> wrote in message
> news:ce******** *************** **@posting.goog le.com...
> > 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
5025
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 double-checked the path to my error log. It is in /var/www/logs/php_error_log Thanks. :) -Wayne Stevenson
3
8885
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 a empty value instead of returning the browser type. Here is the line which i am using in my code and from manual: <?php echo $_SERVER; ?>
21
6220
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 full name is required. Please enter your full name!'); validity = false; frmComments.name.focus();
1
2421
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 was unable to get it fail if a field was blank. My problem now is that while my custom validation control will detect if a field matches my requirement and will display a error message if it doesnt, it wont stop it from being used and sent to my...
1
1426
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" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Weight") %>' /> <asp:RangeValidator ControlToValidate="Weight"
4
2908
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 that sums the values from 2 textboxes. I wanted to implement a simple data validation that would spit out various error messages if the user typed in incorrect data. I managed to vomit out the following code. Yes I know it's beastly,...
11
2986
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 certain fields match certain criteria, and inform the user in different ways when the data is wrong (offcourse, this will be checked on posting the data again, but that's something I've got a lot of experience with). Now, offcourse it's...
7
63110
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
2650
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 Object, ByVal objArgs As ServerValidateEventArgs) if radioDbutton.SelectedItem.Value="yes" Then
0
8397
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8310
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8827
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4315
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1620
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.