[英]How to write a regex that matches at least 10 digits and can have only digits and exclamation mark
I need to write a regex that matches the following conditions: 我需要编写一个符合以下条件的正则表达式:
I can write a regex that matches ten digits like this: 我可以编写一个匹配十个数字的正则表达式,如下所示:
^([0-9]){10,}$
Or that matches only digits and exclamation mark: 或仅匹配数字和感叹号的内容:
^[0-9!]$
But I can't figure out how to join those two together. 但是我不知道如何将这两个结合在一起。
Here is the valid example: 这是有效的示例:
152!1582!!1827
Here is the invalid example: 这是无效的示例:
4!!!!!!!!!!!!!3!
^!*([0-9]!*){10,}$
may be start with zero or more !
可能以零或更多开始
!
, and then have at least 10 repeat of the form a digit and zero or more !
,然后至少有10
a digit and zero or more !
形式a digit and zero or more !
重复a digit and zero or more !
^!*(\\d!*){10,}$
should satisfy your needs. ^!*(\\d!*){10,}$
应该可以满足您的需求。
function validate() { var field = document.getElementById("inputField"); console.log(/^!*(\\d!*){10,}$/.test(field.value)); }
<input type="text" id="inputField"> <button onclick="validate()">Validate</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.