本文介绍了复制粘贴验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在vb.net中创建了一个函数用于字符串验证,整数验证,其中按键事件我限制了一些值,但问题是我的代码在按键事件中工作得很好但是当用户复制错误时文本并粘贴在它接受的文本框中。我想知道如何在按键上验证字符串和整数验证,当用户粘贴错误值时必须提醒它。



我是什么尝试过:



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.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

推荐答案



这篇关于复制粘贴验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-31 10:09