繁体   English   中英

6位数字输入的正则表达式。 输入的每6位数字必须用逗号分隔

[英]Regular expression for 6 digit numeric input. Every 6 digits input numbers must be separated by comma

我的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,并且必须为数字。

提前致谢!

这是您正在寻找的表达

^\d{6}(\,\d{6}){0,2}$

将您的正则表达式创建为搜索组,然后首先检查换行符,然后是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"); } }); 

此模式与您的测试用例以及任何用逗号分隔的6位数字组匹配。

^\d{6}(,\d{6})*$

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM