简体   繁体   English

如何编写至少与10位数字匹配并且只能具有数字和感叹号的正则表达式

[英]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: 我需要编写一个符合以下条件的正则表达式:

  1. At least 10 digits 至少10位数字
  2. Can contain only digits and exclamation mark 只能包含数字和感叹号

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.

相关问题 正则表达式javascript如何写4位数字后跟感叹号“4444!” - Regular expression javascript how to write 4 digits followed by an exclamation mark "4444!" 正则表达式只允许 10 位以下的数字? - Regex to only allow numbers under 10 digits? 如何编写正则表达式以接受 reactjs 中的 5 位或 6 位数字? - how to write regex to accept 5 or 6 digits in reactjs? 仅限数字和连字符的正则表达式 - Regex for digits and hyphen only 8 位数字的正则表达式,然后是 1 个点,之后只有 2 位数字 - Regex for 8 digits and after that 1 dot and after that only 2 digits 如果输入字段不匹配 10 位数字,如何禁用按钮 - How to disable a button if the input field not matches 10 digits JavaScript 中的正则表达式允许最多 10 位数字,数字之间只有一个下划线,并防止在前 5 位数字后输入下划线 - Regex in JavaScript which allow maximum 10 digits, only one underscore in between the digits and prevent entering underscore after the first 5 digits 正则表达式允许最多 10 位数字后跟一个逗号和 3 位以上的数字 - Regex to allow max 10 digits followed by only one comma and 3 more digits JS Regex的后两位与前两位匹配 - JS Regex last two digits matches the first two digits 如何使输入仅接受两个小数并最多包含10个数字? - How to make an input to accept only two decimals and have maximum of 10 digits?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM