C#
C#中如何判断输入的字符是否为数字
private void button6_Click(object sender, EventArgs e) { if (textBox2。Text。Length==0) { MessageBox。Show("X值不能为空!请输入X的值!"); return; } else if (textBox3。
Text。Length==0) { MessageBox。Show("U值不能为空!请输入U的值!"); return;}//判断输入框是否为空 double x, u; if (!double。TryParse(textBox2。Text, out u)) { MessageBox。
Show("U必须为数字!");return; } if (!double。TryParse(textBox3。Text, out x)) { MessageBox。Show("X必须为数字!");return; } if (u = 4) MessageBox。
Show("请输入正确的U值!");//判断输入框中的值是否为数字和是否溢出 } 。
using System。Text。RegularExpressions; /// /// 使用指定正则进行验证 /// /// 正则表达式 /// 待验证字符 /// public static bool RegexValidate(string regexString,string validateString) { Regex regex = new Regex(regexString); return regex。
IsMatch(validateString。Trim()); } bool isNum=RegexValidate("^[0-9]*$",TextBox1。Text); 验证数字:^[0-9]*$ 。
正则表达式 上网搜下,很简单……
答:详情>>