473,657 Members | 2,395 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 1711
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.L ength;
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
1639
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 language="JavaScript" type="text/javascript"> function checkform ( form ) {
11
2519
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 the Min price is greater than the maximum price. 2. The validateForm() function doesn't call isNumber() on the minBaths, maxBaths, minBeds, or maxBeds. 3. Despite errors in input and the validateForm() function returning false, the form is still...
51
8257
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 code? many thx!
2
8387
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 submitting the form to update the database. The server doesn't have the client side value any more. It seems to me that as I begin to write the client side javacript code for form validation and client side editing capabilities in order to save...
2
1643
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 basically that the method that I've designated as the validation routine never gets called so I can't do anything about potentially duff data. I've declared the custom control as:
18
3026
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
1274
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 stop saving the record. For instance if I click on any other button on the form it doesn't stop user from doing so. How can I stop or restrict user to stay in the textbox prebenting any other button or option to be clicked as long as there is a...
1
1610
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 javascript that does this, but it fails when their is a validator monitoring the text box (in firefox, but that's 10% of my visitors).
2
1399
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 the value of the first 4 text boxes is either "0" or greater than 40 - the default of these is "0" so I thought a validation onChange() would help here??
3
7071
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 error occurs. I can check lengths and for nulls but I cant figure this one out. I have tried using a char.IsDigit but that doesnt work, and apparently it isnt as simple as string.contains = 1,2,3 etc. Im really stuck. Can anybody help me out?
0
8395
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
8826
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
7330
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
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
4155
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
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.