正则表达式 数字匹配

1 必须为数字
2 每条记录须以逗号(半角)隔开

如 122,18,123445..18
也就是说 我的输入框中 值 只接受 以 "," (逗号) 分割的由 数字组成的 字符串 如果不限制 字数怎么写呢 也就是没有18位限制条件了.

总结问

1.可包含数字和逗号, 无其他限制的:
^[\d\,]*$
2.以逗号分隔的多个数字,即不能有连续两个逗号, 也不以逗号开头和结尾:
^\d+(\,\d+)*$
3.允许逗号分隔的千分位的整数:
^\d{1,3}(\,\d{3})*$
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-07-26
楼主试试这个,JS实现,希望有帮助
var reg = /^\d+(:?,\d+)*$/ig;
var s = "123,123,123123";
alert(reg.test(s)); //匹配

s = "123";
alert(reg.test(s)); //匹配

s = "123,";
alert(reg.test(s)); //不匹配

s = ",123";
alert(reg.test(s)); //不匹配
第2个回答  2011-07-26
以Vb做为示例的话
需要用二步正则表达式来
set introreg = new regexp
introreg.IgnoreCase=true
introreg.Global =true
introreg.MultiLine = True
introreg.Pattern="[^\d,\.]"
if introreg.test("653,6.3,63.34.0.234") then
'显示不合格
else
set introreg = new regexp
introreg.IgnoreCase=true
introreg.Global =true
introreg.MultiLine = True
introreg.Pattern="(\d+[\.]{1}\d+,)*(\d+[\.]{1}\d+)"
if introreg.test("653,6.3,63.34.0.234") then
'显示合格
else
'显示不合格
end if
end if
第3个回答  2011-07-26
[,]*(\d+)[,]*