在C# 版本的收费系统时,需要加入一些限制,暂时更新这些吧。
只能输入数字和退格
/// <summary>
/// 只能输入数字和退格
/// </summary>
/// <param name="text"></param>
public void InputNumBs(KeyPressEventArgs text)
{
if (text.KeyChar > '9' || text.KeyChar < '0' && text.KeyChar != (char)8)
{
text.Handled = true;
}
return;
}
只能输入英文字母和数字
/// <summary>
/// 只能输入英文字母和数字
/// </summary>
/// <param name="text"></param>
public void InputNumEng(KeyPressEventArgs text)
{
if (text.KeyChar >= 'a' && text.KeyChar <= 'z' || text.KeyChar >= 'A' && text.KeyChar <= 'Z' || text.KeyChar >= '0' && text.KeyChar <= '9' || text.KeyChar == (char)8)
{
text.Handled = false;
}
else
{
text.Handled = true;
}
}
只能输入中文和字母
/// <summary>
/// 只能输入中文和字母
/// </summary>
/// <param name="text"></param>
public void InputHanEng(KeyPressEventArgs text)
{
Regex rg = new Regex("^[\u4e00-\u9fa5]$"); //正则表达式只输入中文
if (!rg.IsMatch(text.KeyChar.ToString()) && text.KeyChar != '\b')
{
text.Handled = true;
}
if (text.KeyChar >= 'a' && text.KeyChar <= 'z' || text.KeyChar >= 'A' && text.KeyChar <= 'Z')
{
text.Handled = false;
}
}
在使用的时候进行调用
private void txtPassword_KeyPress(object sender, KeyPressEventArgs e)
{
limit.InputNumBs(e);
}
//使用的时候调用
1784

被折叠的 条评论
为什么被折叠?



