(注:1.逗号不能是首位或者末位;
2.可以只有1个数字即逗号不出现的情况;
3.输入的只能是数字。)
该如何写正则表达式校验用户输入呢?
纠结了很久,请各位大侠帮帮忙!非常感谢!!
8 个解决方案
#1
^\d+(,\d+)*$
#2
test...
List<string> list = new List<string> { ",1231", "12312,", "1231", "1231,123", "1231,1321,", "fds" };
Regex reg = new Regex(@"^(\d+,?)*(?=\d$)");
foreach (string s in list)
Console.WriteLine(reg.Match(s).Success);
#3
^(\d+,)*\d+$
#4
"^[0-9]+(,[0-9]+)*$"
// C#中\d可代表全角数字
#5
正则表达式不是很懂,帮顶!
#6
#7
#8
问题已经解决了!谢谢各位大侠哈!看来正则表达式还要再加把劲了
#1
^\d+(,\d+)*$
#2
test...
List<string> list = new List<string> { ",1231", "12312,", "1231", "1231,123", "1231,1321,", "fds" };
Regex reg = new Regex(@"^(\d+,?)*(?=\d$)");
foreach (string s in list)
Console.WriteLine(reg.Match(s).Success);
#3
^(\d+,)*\d+$
#4
"^[0-9]+(,[0-9]+)*$"
// C#中\d可代表全角数字
#5
正则表达式不是很懂,帮顶!
#6
#7
#8
问题已经解决了!谢谢各位大侠哈!看来正则表达式还要再加把劲了