Validate and Fix Phone Number with JavaScript
Jun 13, 2022
There is a standard for the phone number called ‘E.164’.
It says that the phone number should have a ‘+’ sign at the start and a maximum of 15 digits.
So, our JavaScript should:
- Check if there is a ‘+’ sign at the start of the string and add it if necessary.
- Do not allow to enter letters and other signs. Only digits.
- Allow to enter up to 15 digits.
The JavaScript code which implements this functionality:
Demo: