Skip to main content

Command Palette

Search for a command to run...

Validate and Fix Phone Number with JavaScript

Updated
1 min read
Validate and Fix Phone Number with JavaScript

Photo by James Sutton on Unsplash

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:

  1. Check if there is a ‘+’ sign at the start of the string and add it if necessary.
  2. Do not allow to enter letters and other signs. Only digits.
  3. Allow to enter up to 15 digits.

The JavaScript code which implements this functionality:

Demo:

More from this blog

Невидимий дизайн: Чому «хмара часток» в Apple Watch — це геніальний інженерний хід

Кожен розробник, який хоч раз налаштовував Apple Watch, відчував цей «wow-ефект». Замість стандартного QR-коду — таємнича анімація, яку iPhone зчитує за частку секунди. Як інженер, я не міг пройти повз і не розібратися: як це працює насправді? Довгий...

Jan 27, 20262 min read
Невидимий дизайн: Чому «хмара часток» в Apple Watch — це геніальний інженерний хід

Як додати графік відключення світла у Календар?

Оновлення Ця стаття втратила актуальність після закінчення відключення світла. Останнє відключення світла у Львові було 30 грудня 2024 р. Ви можете легко додати графіки погодинних відключень світла у місті Львові в Google Календар на Android чи Apple...

Jun 22, 20241 min read
Як додати графік відключення світла у Календар?
V

Viacheslav Kharchenko

20 posts

Ukrainian Tech Lead & Rails dev.

Solving software engineering bottlenecks and daily routine friction — from smart homes to life-ops. Streamlining code and life, one fix at a time.