正则表达式仅匹配数值 [英] Regular expression to match numeric values only
问题描述
Iam尝试正则表达式,只需要接受数字值(带符号的整数和小数)而不是字母表。我尝试使用下面的表达式
[ - +]?[。]?(^ [0-9] + [。]?^ [0-9] +)$
但它不起作用。请帮助
我尝试过:
[ - +] ?[。]?(^ [0-9] + [。]?^ [0-9] +)$
我在C#中试过这个表达式/>
void T1_HTextChanged(object sender,EventArgs e)
{
if(System.Text.RegularExpressions.Regex.IsMatch(T1_H.Text,^ [ - +]?[。]?[0-9] + [。]?[0-9] {0,3} $))
{
MessageBox.Show(请仅输入数字。);
T1_H.Text =;
return;
Iam Trying a Regex Expression which need to Accept only Numeric values (both Integer and Decimal with sign) and not alphabets.I tried with below expression
[-+]?[.]?(^[0-9]+[.]?^[0-9]+)$
but it doesn't work . Kindly Help
What I have tried:
[-+]?[.]?(^[0-9]+[.]?^[0-9]+)$
I tried this expression in C#
void T1_HTextChanged(object sender, EventArgs e)
{
if (System.Text.RegularExpressions.Regex.IsMatch(T1_H.Text, "^[-+]?[.]?[0-9]+[.]?[0-9]{0,3}$"))
{
MessageBox.Show("Please enter only numbers.");
T1_H.Text="";
return;
推荐答案
但它不起作用。请帮助
我尝试过:
[ - +] ?[。]?(^ [0-9] + [。]?^ [0-9] +)
but it doesn't work . Kindly Help
What I have tried:
[-+]?[.]?(^[0-9]+[.]?^[0-9]+)
我在C#中试过这个表达式。
void T1_HTextChanged(对象发送者,EventArgs e)
{
if(System.Text.RegularExpressions。 Regex.IsMatch(T1_H.Text,^ [ - +]?[。]?[0-9] + [。]?[0-9] {0,3}
I tried this expression in C#
void T1_HTextChanged(object sender, EventArgs e)
{
if (System.Text.RegularExpressions.Regex.IsMatch(T1_H.Text, "^[-+]?[.]?[0-9]+[.]?[0-9]{0,3}
))
{
MessageBox.Show(请仅输入数字。);
T1_H.Text =;
return;
"))
{
MessageBox.Show("Please enter only numbers.");
T1_H.Text="";
return;
这篇关于正则表达式仅匹配数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!