Click here to Skip to main content
15,888,221 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I made a function in vb.net for string validation,integer validation in which on "key press event" i restricted some values , but the problem is that my codes work in key press event well but when a user copy the wrong text and paste in text box it accepts. i want to know that how can i validate string and integer validation on the key press , when a user paste wrong values than it must alert.

What I have tried:

i wrote this function

''string validation
Public special_charcters = "~`!@#£€$¢¥§%°^&*()-_+={}[]|\/.:;,""''<>?"

If e.KeyChar <> ControlChars.Back And e.KeyChar <> " " And Keys.Control Then
e.Handled = (Char.IsDigit(e.KeyChar))

Dim ValidInputChar = special_charcters + vbBack
If ValidInputChar.Contains(e.KeyChar) Then
e.KeyChar = Nothing
e.Handled = False
End If
End If
Posted
Updated 27-Jan-17 21:32pm

1 solution

If you want to validate on paste, then you need to handle the TextChanged event: you do not get a KeyPress event for each character of pasted data.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900