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

Text Validation

Can anyone point me in the right direction. I am tring to ensure that the
user input in a textbox is a Number.

Any help would be great
Thanks
God Bless
Dec 7 '05 #1
5 2749
David,

One option is to perform input validation in the textbox’s Validating event.

When the user changes the focus from a textbox (or other control) the
textbox’s Validating event occurs.

In the Validating event you can write code to validate the data in the
textbox. If the user has entered invalid data you can inform the user and
cancel the Validating event.

Canceling the textbox’s Validating event prevents the focus from leaving the
textbox. This forces the user to enter good data into the textbox in order to
continue.

For example, in the txtLength textbox’s Validating event you can test for
invalid input like this:

Private Sub txtLength_Validating(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) _
Handles txtLength.Validating

'If the text in the txtLength textbox is not numeric
If Not IsNumeric(txtLength.Text) Then
'Inform the user that length must be a number
MsgBox("Length must be a number", _
MsgBoxStyle.Exclamation, "Input Error")
'Cancel the Validating event
'to prevent the focus from changing
e.Cancel = True
End If

End Sub

Another option is to perform input validation in a textbox’s Validating
event. But instead of using a message box to display error conditions, use an
ErrorProvider control.

An ErrorProvider control provides an unobtrusive graphical display that a
control contains invalid data.

Kerry Moorman
"David" wrote:
Can anyone point me in the right direction. I am tring to ensure that the
user input in a textbox is a Number.

Any help would be great
Thanks
God Bless

Dec 7 '05 #2
Insert a MaskedTextBox from the VB.NET toolbox. Then go to the property
window & select the mask property. Modify as needed.

William Cruz

*** Sent via Developersdex http://www.developersdex.com ***
Dec 7 '05 #3
Insert a MaskedTextBox from the VB.NET toolbox. Then go to the property
window & select the mask property. Modify as needed.

Just an addition, this is from version VB2005

Cor
Dec 7 '05 #4
David,

In addition of the others, you first have to define what is a Number.

The IsNumeric by instance is very strict in that and except every thing that
can be a numeric value in the culture setting of the client.

Is it meant by instance that it have to be only characters between Chr(0)
and Chr(9), than you cannot use IsNumeric, however maybe is even a dot
allowed in your number.

Just as addition.

Cor
Dec 7 '05 #5
"David" <dm*******@hotmail.com> schrieb:
Can anyone point me in the right direction. I am tring to ensure that the
user input in a textbox is a Number.


<URL:http://groups.google.de/group/microsoft.public.dotnet.languages.vb/msg/577b2c193b8c86d4>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 7 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Otto Krüse | last post by:
Hi everyone, I'm building a GUI in which I want, amongst other things, for people to fill in there postal code. The postal codes of my country (Holland) are in this format: 1234 AB So for the...
1
by: cga1982 | last post by:
I have a text box (for a password) with a validation rule that checks this password against another text box on the form and either lets you continue or tells you that the password is incorrect and...
4
by: Fraggle | last post by:
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
6
by: The Eeediot | last post by:
Hello, Folks... I'm almost becoming a regular to this newsgroup. I am trying to display the contents of an MS-SQL Text field to a TextBox in ASPdotNET. The text in this field contains all...
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: Kris | last post by:
Hi, I have a DataGrid where in each row has couple of text boxes and an update button. Each row is dynamically generated as the number of rows are not known ahead of time. When the user clicks the...
1
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...
9
by: sellcraig | last post by:
Microsoft access 2 tables table "data main" contains a field called "code" table "ddw1" is created from a make table query of "data main" Goal- the data in "code" field in needs to...
3
by: den | last post by:
inner a text element if I want to allow the insertion of only: alphabet's letters a,b,c,.... and A,B,C,... number and this - and this _ and not want space blank and others characters what is...
2
by: devnew | last post by:
hi i am new to tkinter and would like some help with canvas i am doing validation of contents of a folder and need to show the ok/error messages on a canvas resultdisplay =Canvas(...)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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
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
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.