By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,550 Members | 908 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,550 IT Pros & Developers. It's quick & easy.

validation query

P: n/a
A.J
Hi......
(Using vb.net, access as database and datareader to access the data)
Now i got few textboxes having attribute like name,age,phonenumber
etc.I want the txtname to contain only alpha(characters); likewise
txtage to contain number and txtphonenumber be in the format of
####-####-##(ex-9999-9999-99).*I searched the forum for this
validation
query and got the answer that this can be done using
char.Iscontrol/Isdigit...etc..*.I got the Concept(Like it takes a
unicode character 16-bit as argument and returns a boolean value) and
unable to figure out how to implement this or is there any other way of

implementing this concept.
As i am a newbie so please explain this concept in detail.
Thankx in advance!!!!

Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
what you do is override the OnKeyPress method and then set e.Handled =
True for cases that you wish to exclude.

a quick example to allow only numbers...

Public Class TextBox_NumericOnly : Inherits
System.Windows.Forms.TextBox
Protected Overrides Sub OnKeyPress(ByVal e As KeyPressEventArgs)
If (Char.IsNumber(e.KeyChar)=False) Then e.Handled=True
End Sub
End Class

you don't have to create your own control -- you can simply Override
the method, but since this is a common scenario, you may want to write
your own so that you can re-use it...

Nov 21 '05 #2

P: n/a
A.J


stand__sure wrote:
what you do is override the OnKeyPress method and then set e.Handled =
True for cases that you wish to exclude.

a quick example to allow only numbers...

Public Class TextBox_NumericOnly : Inherits
System.Windows.Forms.TextBox
Protected Overrides Sub OnKeyPress(ByVal e As KeyPressEventArgs)
If (Char.IsNumber(e.KeyChar)=False) Then e.Handled=True ' What this "handled" method suppose to do?? End Sub
End Class

you don't have to create your own control -- you can simply Override
the method, but since this is a common scenario, you may want to write
your own so that you can re-use it...


Nov 21 '05 #3

P: n/a
Hi,

Here is a link to a few free masked edit boxes.

http://www.codeproject.com/vb/net/cpflexmaskeditbox.asp
http://www.codeproject.com/useritems/MaskedTextBox.asp
Ken
----------------------
"A.J" <aj********@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Hi......
(Using vb.net, access as database and datareader to access the data)
Now i got few textboxes having attribute like name,age,phonenumber
etc.I want the txtname to contain only alpha(characters); likewise
txtage to contain number and txtphonenumber be in the format of
####-####-##(ex-9999-9999-99).*I searched the forum for this
validation
query and got the answer that this can be done using
char.Iscontrol/Isdigit...etc..*.I got the Concept(Like it takes a
unicode character 16-bit as argument and returns a boolean value) and
unable to figure out how to implement this or is there any other way of

implementing this concept.
As i am a newbie so please explain this concept in detail.
Thankx in advance!!!!
Nov 21 '05 #4

P: n/a
it stops the character from being passed to the next event handler
(i.e. it is handled and no further processing is required).

you can also do field-level testing in the Validating event handler
(normally just to display a MessageBox describing the error and to
return focus to the control via e.Cancel = True)

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.