473,505 Members | 15,976 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple Text box validation

11 New Member
Hi there a quick simple question, i need to be able to validate a textbox

The user must enter a number within the range 0001 to 9999 only.

And in the 4 number format XXXX , e.g. if they enter the number 11 i need it to be formated 0011.

thanks
Mar 30 '08 #1
5 1703
balabaster
797 Recognized Expert Contributor
Hi there a quick simple question, i need to be able to validate a textbox

The user must enter a number within the range 0001 to 9999 only.

And in the 4 number format XXXX , e.g. if they enter the number 11 i need it to be formated 0011.

thanks
Is this on a Windows form or on a Web page? If it's on a web page, do you need client side validation or server side validation?
Mar 30 '08 #2
insomnia
11 New Member
Is this on a Windows form or on a Web page? If it's on a web page, do you need client side validation or server side validation?

Sorry balabaster, it is on a vb.net form, i simply need to validate the data a user enters in to one of the fields on a form.

the format must be numerical and 4 digits long.

----------

and how could i disable a "space" being used

eg. if the user types "two apples" rather than "twoapples"

---------

cheers
Mar 30 '08 #3
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
vb.net form? Will presume that it is a windows application.

You can use regex to do that
this expression ^[0-9]{4}$ will limit the user to enter only digits into the textbox and that is limited to 4 digits in total.
Mar 31 '08 #4
insomnia
11 New Member
Thanks all sorted :-)

I used a combination of :

Expand|Select|Wrap|Line Numbers
  1. If Not IsNumeric(Textbox.Text) Or Textbox.Text = "" 
And :

Expand|Select|Wrap|Line Numbers
  1. Textbox.Text = Format(Convert.ToInt32(Textbox.Text), "0000")

in the end to achieve my goal.

cheers again
Mar 31 '08 #5
todashah
26 New Member
Hi there a quick simple question, i need to be able to validate a textbox

The user must enter a number within the range 0001 to 9999 only.

And in the 4 number format XXXX , e.g. if they enter the number 11 i need it to be formated 0011.

thanks
To perform this kind of validation in C# write down following code in Leave event of textbox.

int l = textBox1.Text.Length;
if (l != 4 || l < 0 || l > 9999)
MessageBox.Show("Invalid No");
else
MessageBox.Show("Valid No");

Make necessary changes in this code so it is execute in VB.net..
Bye...Enjoy Coding
Apr 1 '08 #6

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

Similar topics

3
1627
by: Marc Llenas | last post by:
Hi there, I'm stuck on a validation function for a form and I cannot figure out what the problem is. The page is in ASP. Any ideas? The function being called is: <script...
11
2496
by: greg.scharlemann | last post by:
I've been playing with this form validation method for a while and have tried an array of things but haven't had any luck with a couple items. 1. The validateForm() function doesn't detect when...
51
8210
by: Alan | last post by:
hi all, I want to define a constant length string, say 4 then in a function at some time, I want to set the string to a constant value, say a below is my code but it fails what is the correct...
2
8374
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
2
1638
by: SimonH | last post by:
Hi All, I'm having problems getting a custom validator to work. I'm hoping someone could perhaps notice what I've missed. I only want to provide a server side validation method. The problem is...
18
3014
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
8
1267
by: Abul Hasan | last post by:
Hello everyone, I have placed simple validation through ErrorProvider Class on my textBoxes to check whether ther r empty or not Error Provider Class check and catches the error but it doesn't...
1
1604
by: Joel Barsotti | last post by:
Is there anything builtin to ASP.net that allows you to tie a text box to a button so when you press enter in the text box it emulates clicking a near by button. I've coded up some client side...
2
1390
by: argylew | last post by:
This is simple, SO simple but I dont know how to do it!! I have 5 text boxes on one page (all contain numbers). The 5th box is the sum of the first four. I need to validate it so that the...
3
7062
by: meripu1 | last post by:
There was no way to post in the C# forum so I figured I had to post here. I am having trouble with simple validation. All I want to do is validate a text box so that if a number is entered, an...
0
7103
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...
0
7370
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
7021
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
5614
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,...
0
4701
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...
0
3188
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
3177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
409
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.