复制粘贴验证

编程入门 行业动态 更新时间:2024-10-26 11:25:22
本文介绍了复制粘贴验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

更多推荐

复制粘贴验证

本文发布于:2023-11-25 01:24:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627745.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!