我在vb中创建了一个函数用于字符串验证,整数验证,其中按键事件我限制了一些值,但问题是我的代码在按键事件中工作得很好但是当用户复制错误时文本并粘贴在它接受的文本框中。我想知道如何在按键上验证字符串和整数验证,当用户粘贴错误值时必须提醒它。 我是什么尝试过: i写了这个函数 ''字符串验证 公共special_charcters =〜`!@#£€€¢%^ ^& *()-_ + = {} [] | \ /.:;,\"\"''&&&&& ;? 如果e.KeyChar<> ControlChars.Back和e.KeyChar<> 和Keys.Control然后 e.Handled =(Char.IsDigit(e.KeyChar)) Dim ValidInputChar = special_charcters + vbBack 如果ValidInputChar.Contains(e.KeyChar)那么 e.KeyChar =没什么 e.Handled = False 结束如果 结束如果
I made a function in vb 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
推荐答案¢¥§%°^& *() - _ + = {} [ ] | \ /.:;,\"\"''& lt;>? 如果e.KeyChar<> ControlChars.Back和e.KeyChar <>和Keys.Control然后 e.Handled =(Char.IsDigit(e.KeyChar)) 昏暗ValidInputChar = special_charcters + vbBack 如果ValidInputChar.Contains(e.KeyChar)那么 e.KeyChar =没什么 e.Handled = False 结束如果 结束如果 ¢¥§%°^&*()-_+={}[]|\/.:;,""''<>?" 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
如果你是要在粘贴上验证,然后你需要处理TextChanged事件:你没有为粘贴数据的每个字符获得一个KeyPress事件。 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.
更多推荐
复制粘贴验证
发布评论