Hello, I have built the following logic to mask a US phone number and validate it with regex code. It works fine when I enter in 9876543210 format and changes accordingly to (987) 654-3210. However, when I enter +19876543210 it returns +1 (987) 765-4321. The third digit of the area code gets repeated and the last digit is gone. Can someone please help me with this ?
The regex code I am using is
var regexCode = /^\s*(?:\+?(\d{1,3}))?[- (]*(\d{3})[- )]*(\d{3})[- ]*(\d{4})(?: *[x/#]{1}(\d+))?\s*$/;










