正则表达式。 [英] Regular expression.
本文介绍了正则表达式。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我需要验证文本框的输入。
我希望用户只输入数字。
我可以用我的正则表达式使用正则表达式吗?
非常感谢
杰克
Hello,
I need to validate the input of my text box.
I want the users to enter only numbers.
Wich regular expression can i use with my Regex class?
many thanks
Jack
推荐答案
使用\d
或\d +如果你想要一个或多个数字
" Jack詹森和QUOT; < JA ********* @ mail.dk>一个écritdansle message de
news:uV ************** @ TK2MSFTNGP15.phx.gbl ...
use \d
or \d+ if you want 1 or more digits
"Jack jensen" <Ja*********@mail.dk> a écrit dans le message de
news:uV**************@TK2MSFTNGP15.phx.gbl...
你好,
我需要验证我的文本框的输入。
我希望用户只输入数字。
我的正则表达式可以用于我的Regex类吗?/ >
非常感谢
Jack
Hello,
I need to validate the input of my text box.
I want the users to enter only numbers.
Wich regular expression can i use with my Regex class?
many thanks
Jack
谢谢,
i写道下面的代码,但它总是进入错误块,无论我怎么写。
我做错了什么?
string exp = @" \d +" ;;
正则表达式=新的正则表达式(exp);
String s = tbOPostalCode.Text ;
匹配m = num.Match(s);
if(!m.Success)
{
MessageBox.Show(邮政编码必须是数字。,邮编错误,
MessageBoxButtons.OK,MessageBoxIcon.Error);
}
thanks,
i wrote the code below but it always enters the error block no matter what i
write.
what i''m doing wrong?
string exp = @"\d+";
Regex num = new Regex(exp);
String s =tbOPostalCode.Text;
Match m = num.Match(s);
if (! m.Success )
{
MessageBox.Show("The zip code must be a number.", "Zip code error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
>
这是我在我的应用程序中使用的方法
public static bool IsNumeric(string toValidate)
{
正则表达式=新正则表达式(@" [^ \d]");
return!pattern.IsMatch(toValidate);
}
此外邮政编码也不总是数字。如果用户输入了怎么办?
55555-2345
Here is a method that I use in my applications
public static bool IsNumeric(string toValidate)
{
Regex pattern = new Regex(@"[^\d]");
return !pattern.IsMatch(toValidate);
}
Also zip codes aren''t always numeric. What if the user inputed
55555-2345
这篇关于正则表达式。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文