I am working on a chat application where user have to fill the form before he/she begins the chat. Validation of each form field happens once user enters the value in respective form field. One of the form field is phone number and for which I wrote a regular expression as following.
var phoneRegex = RegExp(/^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,10}$/im);
Regex should return 'true' for following phone numbers
+11234567890
- 10 digits with area code1234567890
- 10 digits233445678912
- 12 digits2334456789122222
- 16 digits
My chat application works for first 3 numbers but doesn't work for 16 digit phone number. I am not a huge fan of regex and have limited understanding of it hence I want to to know if my regex has any fault? And if yes then how can I fix it?