|
-
Oct 26th, 2002, 10:40 PM
#1
Thread Starter
Addicted Member
Pasting in to a textbox
I want to make my program check whats being pasted in to my textbox and remove all disallowed characters, for example, I need to to remove all characters except numbers and commas. What would be the best way to carry this out?
-
Oct 26th, 2002, 10:43 PM
#2
PowerPoster
use the Isnumeric function in the textbox change event
-
Oct 26th, 2002, 10:45 PM
#3
Thread Starter
Addicted Member
-
Oct 26th, 2002, 10:49 PM
#4
PowerPoster
commas dont falsify the isnumeric test. try this:
VB Code:
Private Sub Text1_Change()
If Not IsNumeric(Text1.Text) Then
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End If
End Sub
-
Oct 26th, 2002, 10:51 PM
#5
Fanatic Member
Maybe trap for keystrokes. Detect if a numeric character is pressed and cancel it.
- If at first you dont succeed, then give up, cause you will never will!
-
Oct 26th, 2002, 11:00 PM
#6
Thread Starter
Addicted Member
Well its a good thing that commas are allowed, but i cant allow periods... I guess I'll have to use a loop to go through each character pasted and detect whether its a number/comma or not then decide if it goes through So much work for such a late hour
-
Oct 26th, 2002, 11:08 PM
#7
PowerPoster
Originally posted by Xerpher
Well its a good thing that commas are allowed, but i cant allow periods... I guess I'll have to use a loop to go through each character pasted and detect whether its a number/comma or not then decide if it goes through So much work for such a late hour
try this:
VB Code:
Private Sub Text1_Change()
If Not IsNumeric(Text1.Text) Then
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End If
Text1.Text = Replace(Text1.Text, ".", "")
End Sub
-
Oct 26th, 2002, 11:48 PM
#8
Thread Starter
Addicted Member
The replace! thats it! I dont know why I didn't think of that before, I'll make a for each loop that replaces all disallowed characters stored in an array with nothing!
Thanks for the inspriration Muddy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|