473,487 Members | 2,671 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Validating a text box

347 Contributor
I have a form that has a text box that I want to only allow users to enter a date and then a MessageBox.Show stating that their data was submitted when they press a submit button. I know that you can do this with a regular expression validation but I have no idea how to do this in Visual Basic. Can anyone offer how to do that?

Thank you

Doug
Feb 23 '11 #1
2 1569
Kalen Viljoen
12 New Member
To only allow them to enter the date you would have to watch the keyPress event. But you can check that what they entered is a date after they press the submit button by using:

If IsDate(TextBox1.Text) = True Then
MsgBox("You entered a date")
Else
MsgBox("Please enter a date")
End If
Feb 25 '11 #2
BlackLibrary
16 New Member
Are you restricted to just using a text box? Why not use the right tool for the right job. Use a datepicker.

In any case, watching the keypress will be tough, and you have to think ahead. Which format will they enter the date? January 3rd, 2011? 1/3/11? 01/03/2011?

You can't easily restrict the key presses as they are all over the place with that. IMO, your best bet, short of using a date control, is to allow them free entry, then on lost focus, test that value as such.

Take a look also, at the masked textboxes, if it must look like a text box.

Take a look, finally, at the link below. Its on how to convert the textbox.text (a string) into a date. Note, in all cases, "January 5th, 2011" will fail as a date. Cant convert string to date without parsing it.

http://msdn.microsoft.com/en-us/library/w2sa9yss.aspx
Mar 25 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
13981
by: Mark | last post by:
Hi, Im trying to validate a form, all the validating works apart from one field. This particular field must consist of the first 2 characters as letters, & the following 5 as numbers. And if it...
6
5770
by: Alex Bink | last post by:
Hi, I have a validating event on a textbox in which I want to prevent the user to leave the textbox without entering the right data. Only if he clicks on another specific control he is allowed...
2
1110
by: Rajesh | last post by:
I have bunch of textboxs in a form.Now i want ot validate these textboxes.These textboxes i am entering string as well as numeric values.How can i validate string and numeric values? Thanks for...
1
1292
by: lenin42001 | last post by:
Help i've just done a basic calculator with three textboxes a label & a button, basically when you add a number in textbox1 to the one in textbox2 it appears in textbox3 .........now the question...
0
883
by: bobby421 | last post by:
Hi, I have a master page and content page. In content page I have to validate the text boxes for name,address, phone number and email address etc. But as content pages doersn't have html section...
3
1056
by: ruvini218 | last post by:
How can i make a text box to accept only numeric values?
4
3295
by: ravindarjobs | last post by:
Hi friends, i am using .net 2005 but we dont use validation controls. my requirement is that i have to limit user entering only alpha values in "first name" and "last name" fields. the page...
8
2036
by: lolodede | last post by:
hi thank you very much for replying quickly if i could do anything tell me im new to javascript so i have problem with validating text box to accept only positive numbers and not more than 1000 ...
10
3220
by: chandhseke | last post by:
I have developed a web page using ASP classic, I am using VBScript for database connectivity... The web application is working fine, but i am now working on a new enhancement requirement where i need...
0
7137
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
7181
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...
1
6846
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
5442
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4874
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...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
600
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
267
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...

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.