Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / July 2007

Tip: Looking for answers? Try searching our database.

Restrict input charaters in textbox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Cylix - 05 Jul 2007 10:13 GMT
I would like to let the client input numeric, "," and "-" in the
textbox,
all the other else charater will take no effect on the value of the
textbox.

How can I do so?

Thanks a lot!
rowe_newsgroups - 05 Jul 2007 11:24 GMT
> I would like to let the client input numeric, "," and "-" in the
> textbox,
[quoted text clipped - 4 lines]
>
> Thanks a lot!

The "standard" way is to handle the textbox's keydown, keypress, or
keyup events and trap the invalid keys there and prevent them from
going into the textbox. You may also have to trap paste events - it's
been a while and I don't remember if the above will catch pasted text
or not.

Thanks,

Seth Rowe
Cor Ligthert [MVP] - 05 Jul 2007 11:43 GMT
Hi,

You can search this newsgroup with this problem,

http://groups.google.nl/group/microsoft.public.dotnet.languages.vb/search?group=
microsoft.public.dotnet.languages.vb&q=numeric+textbox


There you will find the solution as Seth has written.

Cor

>I would like to let the client input numeric, "," and "-" in the
> textbox,
[quoted text clipped - 4 lines]
>
> Thanks a lot!
Mr. Arnold - 05 Jul 2007 11:49 GMT
>I would like to let the client input numeric, "," and "-" in the
> textbox,
[quoted text clipped - 4 lines]
>
> Thanks a lot!

You put something like the code below  in the Textbox Keydown event

If (e.KeyChar < "0" OrElse e.KeyChar > "9") _
   AndAlso e.KeyChar <> ControlChars.Back AndAlso e.KeyChar <> "." Then
   'cancel keys
   e.Handled = True
End If
Mr. Arnold - 05 Jul 2007 11:54 GMT
>>I would like to let the client input numeric, "," and "-" in the
>> textbox,
[quoted text clipped - 4 lines]
>>
>> Thanks a lot!

Sorry, that would be put in the Textbox KeyPress event is the right place.

> If (e.KeyChar < "0" OrElse e.KeyChar > "9") _
>    AndAlso e.KeyChar <> ControlChars.Back AndAlso e.KeyChar <> "." Then
>    'cancel keys
>    e.Handled = True
> End If
Cylix - 06 Jul 2007 02:29 GMT
Sorry about such silly question,
I just don't know that I can done the task by e.handled = true.

Thanks a lot.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.