简体   繁体   中英

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).

I tried but my best result was 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}$/

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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