在codebehind文件中验证c#asp.net2.0中的数字和字母 [英] to validate for numbers and alphabets in c# asp.net2.0 in codebehind file

查看:101
本文介绍了在codebehind文件中验证c#asp.net2.0中的数字和字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在代码隐藏文件中验证c#asp.net2.0中的数字和字母,文本框应该接受所有数字,字母,特殊字符......但是如果文本框中只包含数字错误消息,则文本框不应该只包含数字框应该被抛出..请帮我如何在代码隐藏文件中的c#.net中编码

解决方案





试试这个:

  bool  includesNotOnlyNumeric = Regex.IsMatch(textBox.Text,< span class =code-string> @  \ D); 
if (includesNotOnlyNumeric)
{
// 不显示提示框
}
else
{
// 显示提示框
}


你可以使用正则表达式:

  string  str = myTextBox.Text ; 
Regex includesNonNumeric = new 正则表达式( @ [^ \d]);
if (includesNonNumeric.IsMatch(str))
{
// 确定
}
其他
{
// 失败
}


to validate for numbers and alphabets in c# asp.net2.0 in codebehind file,the textbox should accept all numbers,alphabets,special characters...but textbox should not contain only numbers if it contains only numbers error message in alert box should be thrown..please help me how to code in c#.net in code behind file

解决方案

Hi,

Try this:

bool includesNotOnlyNumeric = Regex.IsMatch(textBox.Text, @"\D");
if (includesNotOnlyNumeric)
{
    // don't show an alert box
}
else
{
    // show an alert box
}


You could use a Regex:

string str = myTextBox.Text;
Regex includesNonNumeric = new Regex(@"[^\d]");
if (includesNonNumeric.IsMatch(str))
    {
    // OK
    }
else
    {
    // Failed
    }


这篇关于在codebehind文件中验证c#asp.net2.0中的数字和字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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