样本编码以限制特殊字符 [英] Sample codings to restrict special characters

查看:107
本文介绍了样本编码以限制特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在vb6和vb.net中限制特殊字符的示例编码?

Sample codings to restrict special characters in vb6 & vb.net?

推荐答案

它们不是唯一的方法,也是一种实现它们的方法...

VB6:以所需的方式使用Ascii值!例如:
They are not the only way, one od the ways to do them...

VB6: Use Ascii values the way you want! Ex:
Option Explicit

'This will only accepts the alphabets and no other key is allowed.
Private Sub Text1_KeyPress(KeyAscii As Integer)
    If Not KeyAscii >= 65 And KeyAscii < 90 Then
        KeyAscii = 0
    End If
End Sub



VB.NET:使用KeyPressed进行验证...



VB.NET: Use KeyPressed for validation...

''Textbox KeyPress
'' Allow number 0-9 plus backspace, Del + Home + End will be accepted also
Dim ValidInputChar = "0123456789." + vbBack
If not ValidInputChar.Contains(e.KeyChar) then
    e.KeyChar=Nothing           
End If


此功能限制用户插入特殊字符

if((!char.IsLetterOrDigit(e.KeyChar))&&((!(e.KeyChar ==(char)Keys.Back)))
{
e.Handled = true;

}
其他
{
e.Handled = false;

}
This function restrict user from inserting special characters

if ((!char.IsLetterOrDigit(e.KeyChar))&&(!(e.KeyChar==(char)Keys.Back)))
{
e.Handled = true;

}
else
{
e.Handled = false;

}


这篇关于样本编码以限制特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆