-1

I currently have this in a contact form and it's working properly with US +1 country code number. My question is: How can I make this work for double digits international numbers?. I've tried editing but it doesn't seem to work correctly.

onkeyup="this.value=this.value.replace(^\+?\d*$')" pattern=  "[+]{1}[1]{1}[0-9]{10}"

I need to send the + sign and the country code back to a CRM. I also need to force user to include a number. Thanks in advance.

MonkeyZeus
  • 20,375
  • 4
  • 36
  • 77
Home Plus
  • 1
  • 1
  • Side note: `{1}[1]` is equivalent to just `1`. Now, regarding the double digits, you can just use `\+\d{2}` and then the rest of the pattern. For example, if the number after the country code is always 10 digits, then `^\+\d{12}$` should do the trick. If that's not good enough, there are many questions about matching phone numbers that have been asked before. Here's [one example](https://stackoverflow.com/q/2113908/8967612). – 41686d6564 stands w. Palestine Dec 03 '20 at 19:50
  • @41686d6564 `^\+\d{12}$` would enforce a 12 digit phone number which is very shortsighted. `^\+\d{10,12}$` would allow for an optional single or double digit country code. – MonkeyZeus Dec 03 '20 at 20:10

2 Answers2

0

This regex checks if it is a valid phone number and it also valid for international codes like +1 or +38:

+(9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d| 2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]| 4[987654310]|3[9643210]|2[70]|7|1)\d{1,14}$

Ostap Filipenko
  • 235
  • 5
  • 21
0

@MonkeyZeus, your code worked, ^\+\d{10,12}$but, I need to avoid the user erasing complete number and still sending the form in. Do you have another suggestion. My original code worked perfectly but, I couldn't get International codes to send. TY

Home Plus
  • 1
  • 1