我的UI要求输入User_ID和Supplier_ID,我想要一个字符串验证接受Supplier_ID的输入,如下所示:
1st scenario: 123456
2nd scenario: 123456,098765
3rd scenario: 123456,098765,345678
虽然它不应接受如下输入:
1st scenario: Any number less than 6 digits like 123
2nd scenario: Any number more than 6 digits 1234567
3rd scenario: Inputs with comma in the end or even at the beginning - 123456,098765,345678, or ,098765,345678
我将在下面的查询中使用Supplier_ID的输入:
UPDATE ABC.Items
SET Crit_Limit = 'Y'
WHERE User_ID = 'userID'
AND Supplier_ID in (suppID)
变量suppID将携带来自UI Supplier_ID的输入,因此查询将如下所示:
UPDATE ABC.Items
SET Crit_Limit = 'Y'
WHERE User_ID = '007'
AND Supplier_ID in (123456,098765,345678)
无论如何,字段Supplier_ID的长度为6,必须为数字。
提前致谢!
答案 0 :(得分:0)
这是你正在寻找的表达
^\d{6}(\,\d{6}){0,2}$
答案 1 :(得分:0)
将您的正则表达式设置为搜索组,首先检查换行符后跟6位数字,然后检查,
后跟6位数组。
['123456',
'123456,098765',
'123456,098765,345678',
'123456,0987s65,345678',
'12345,098765,345678',
'123456/098765'
]
.forEach(function(line) {
if (line.toString().replace(/(^\d{6}(,\d{6})*)/gm, '').length < 1) {
console.log(line, "matches");
} else {
console.log(line, "does not match");
}
});
&#13;
答案 2 :(得分:0)
此模式与您的测试用例以及由逗号分隔的任意数量的6位数组匹配。
^\d{6}(,\d{6})*$