PDA

Click to See Complete Forum and Search --> : Validate pasted data


aruser
Oct 9th, 2002, 09:31 AM
I am tring to validate the data being pasted into a text field before it is written to the field.

I need to disable the paste of non numeric characters even if pasted from the clipboard.

I already disabled the Ctrl+V option, but I still have the paste option in the right-click menu opened for the textbox.

Thanks

Jeremy Martin
Oct 9th, 2002, 10:05 AM
I suppose you could scan through the textbox and see if any of the characters are not numbers on the textchanged event. Then either remove the the letters/non numeric characters or take everything out of the textbox.

example:
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim s As String
Dim c As Char

For Each c In TextBox1.Text
If c = "1" Or c = "2" Or c = "3" Or c = "4" Or c = "5" Or c = "6" Or c = "7" Or c = "8" Or c = "9" Or c = "0" Then
s &= c
End If
Next
TextBox1.Text = s
End Sub

Jeremy