[英]Javascript Regex to validate string length and last 3 characters as digits
How should I write regex to validate below conditions: 我应该如何编写正则表达式来验证以下条件:
eg: Valid strings: 1234, EC123, 1YC898, 001234 例如:有效字串:1234,EC123、1YC898、001234
So far, I have tried below regex, but seems like I am missing something? 到目前为止,我已经尝试过使用正则表达式,但是好像我缺少了什么?
(^[a-zA-Z0-9]{4,6})?\d{3}$
You can use: 您可以使用:
^[a-zA-Z0-9]{1,3}\d{3}$
^[a-zA-Z0-9]{1,3}
will match 1 to 3 alpha-numerals at the start ^[a-zA-Z0-9]{1,3}
将在开始时匹配1到3个字母数字 \\d{3}$
will match 3 digits at the end of your input \\d{3}$
将在您输入的末尾匹配3位数字
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.