最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp.net c#与vb.net 只能输入英文和数字函数
时间:2022-06-25 05:03:50 编辑:袖梨 来源:一聚教程网
本文章也是针对于asp教程.net来做的,就是关于asp.net教程 c#与vb.net 只能输入英文和数字函数,第一款是c#限制只能输入数字与英文,后一示是vb.net做的,原理都一个个字符然后判断他的内码值如下实例。
c#
private void textbox1_textchanged(object sender, eventargs e)
{
char[] clist = textbox1.text.tochararray();
string newstr = "";
for (int i = 0; i < clist.length; i++)
{
int ascii = (int)clist[i];
if (ascii > 127)
{
clist[i] = '';
}
newstr += clist[i].tostring();
}textbox1.text = newstr;
}
vb.net
function valitext(keyin as integer, validatestring as string, editable as boolean) as integer
dim validatelist as string
dim keyout as integer
if editable = true then
validatelist = ucase(validatestring) & chr(8)
else
validatelist = ucase(validatestring)
end if
if instr(1, validatelist, ucase(chr(keyin)), 1) > 0 then
keyout = keyin
else
keyout = 0
end if
valitext = keyout
end function
调用方法
private sub txtmoney_keypress(keyascii as integer)
keyascii = valitext(keyascii, "0123456789.", true)
end sub
private sub txtid_keypress(keyascii as integer)
keyascii = valitext(keyascii, "0123456789-abcdefghijklmnopqrstuvwxyz", true)
end sub
相关文章
- 《燕云十六声》红尘无眼完成图文攻略 12-25
- 《燕云十六声》阴阳如影完成图文攻略 12-25
- 《燕云十六声》悬檐之下四架椽屋图文攻略 12-25
- 《燕云十六声》2024最新公测时间介绍 12-25
- 《燕云十六声》有没有藏宝阁 12-25
- 《燕云十六声》制作公司介绍 12-25