简体   繁体   English

带有长度和某些特定字符的正则表达式数字

[英]Regex digits with length and some specific characters

I have a phone number input field where it must: 我必须在其中输入电话号码:

  1. Allows spaces and "-" and "+" characters. 允许空格以及“-”和“ +”字符。
  2. Have 12 characters max including the special characters (ex +12345678910). 最多12个字符,包括特殊字符(例如+12345678910)。

I tried but my best result was ng-pattern="/^\\+?\\d{0,11}?$/" . 我尝试过,但最好的结果是ng-pattern="/^\\+?\\d{0,11}?$/"
How to make this work? 如何使这项工作?

Seems like you're trying to match a phone number? 好像您要匹配电话号码? Maybe this is helpful: What regular expression will match valid international phone numbers? 也许这会有所帮助: 哪些正则表达式将与有效的国际电话号码匹配?

Otherwise, if no particular order or restrictions for your numbers, + , - or spaces, this should do the work: /^[0-9\\+\\-\\s]{1,12}$/ 否则,如果对您的数字+-或空格没有特定的顺序或限制,则应执行以下操作: /^[0-9\\+\\-\\s]{1,12}$/

https://regex101.com/r/kuc5OF/2 https://regex101.com/r/kuc5OF/2

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

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