我需要检查值
值必须包含小写字母数字字符,' - '或'。',并且必须以字母数字字符开头和结尾
(SELECT SUM(CASE WHEN (msg_status = 0) THEN 1 ELSE 0 END) FROM svc_sms_msg WHERE sms_pk = svc_sms.sms_pk) as cnt_initial");
(SELECT SUM(CASE WHEN (msg_status = 1) THEN 1 ELSE 0 END) FROM svc_sms_msg WHERE sms_pk = svc_sms.sms_pk) as cnt_pending");
(SELECT SUM(CASE WHEN (msg_status = 2) THEN 1 ELSE 0 END) FROM svc_sms_msg WHERE sms_pk = svc_sms.sms_pk) as cnt_sended");
这个正则表达式工作正常,但是如果我输入两个或更多字符就是如此,但即使是一个字符我也需要这个工作
我该怎么做?
谢谢!
答案 0 :(得分:1)
此正则表达式在前面需要一个字母数字字符。并且在中间允许任意数量的字母数字字符,点或短划线,只要它后面跟着一个字母数字字符。
const regularExpressionTemplate = /^[a-z0-9]([a-z0-9\.\-]*[a-z0-9])?$/;
const values = [
'test',
't-t',
't-2',
't2',
't',
'3',
't@t',
'@'
];
const result = values.map(value => regularExpressionTemplate.test(value));
console.log(result);