logo

  • Hỏi Đáp
  • Kiến Thức
  • Sức Khỏe
  • Tử Vi
  • Công Nghệ
No Result
View All Result
logo
No Result
View All Result
Trang chủ simple way to validate phone numbers in php

Simple way to validate phone numbers in php

by Admin _ December 25, 2022

The regular expressions below can be used khổng lồ validate if a string is a valid phone number format and to extract a phone number from a string. Please lưu ý that this validation can not tell if a phone number actually exists.


Bạn đang xem: Simple way to validate phone numbers in php

*

*

*

*

*

Xem thêm: Tinh Ý Phát Hiện 10 Dấu Hiệu Con Trai Không Thích Bạn Thích Không Thích Bạn

The basic international phone number validation

A simple regex lớn validate string against a valid international phone number format without delimiters và with an optional plus sign:


// Validate phone number$phone_number_validation_regex = "/^\+?<1-9><0-9>7,14$/"; echo preg_match($phone_number_validation_regex, "+12223334444"); // returns 1// Extract phone number from a string$extract_phone_number_pattern = "/\+?<1-9><0-9>7,14/";$string_to_match = "You can reach me out at +12223334444 and +56667778888";preg_match_all($extract_phone_number_pattern, $string_to_match, $matches);// matches<0> is <"+12223334444", "+56667778888">

The more complex phone number validation

This regular expression will match phone numbers entered with delimiters (spaces, dots, brackets, etc.)


// Validate phone number$phone_number_validation_regex = "/^\+?\d1,4?<-.\s>?\(?\d1,3?\)?<-.\s>?\d1,4<-.\s>?\d1,4<-.\s>?\d1,9$/";echo preg_match($phone_number_validation_regex, "+1 (615) 243-5172"); // returns 1
Extra information about validating phone number

While validation of phone numbers using regex can give a possibility to check the format of the phone number, it does not guarantee that the number exists.

There might be also an option to leave a phone number field without any validation since some users might have:

More complex phone numbers with extensionsThe different phone numbers for calling them on a different time of day

Create an internal tool with UI Bakery

Discover UI Bakery – an intuitive visual internal tools builder.

Share Tweet Linkedin Pinterest
Previous Post

How to display mysql table data tutorial

Next Post

Bài 05: tìm hiểu về public, protected, private trong lập trình oop

CÙNG CHUYÊN MỤC

form register php

Form register php

09/04/2021
fantastic blog (cms) in php with source code

Fantastic blog (cms) in php with source code

28/04/2021
validate form php javascript

Validate form php javascript

28/04/2021
http diendanlequydon com viewtopic php style 6

Http diendanlequydon com viewtopic php style 6

28/04/2021
cách cài đặt php 7

Cách cài đặt php 7

24/01/2023
rövid videó

Rövid videó

23/01/2023
installing apache php mysql on ubuntu 18

Installing apache php mysql on ubuntu 18

20/01/2023
tính kế thừa trong oop php

Tính kế thừa trong oop php

20/01/2023

Newsletter

The most important automotive news and events of the day

We won't spam you. Pinky swear.

Chuyên Mục

  • Hỏi Đáp
  • Kiến Thức
  • Sức Khỏe
  • Tử Vi
  • Công Nghệ

News Post

  • Phần mềm autodesk

About

Chúng tôi tạo ra trang web nhằm mục đích mang lại kiến thức bổ ích cho cộng đồng, các bài viết được sưu tầm từ nhiều nguồn trên internet giúp mang lại kiến thức khách quan dành cho bạn

©2023 darkedeneurope.com - Website WordPress vì mục đích cộng đồng

Liên Hệ - Giới Thiệu - Nội Quy - Bảo Mật

No Result
View All Result
  • Trang chủ
  • Chuyên mục
    • Hỏi Đáp
    • Kiến Thức
    • Sức Khỏe
    • Tử Vi
    • Công Nghệ
  • Lưu trữ
  • Liên hệ

© 2023 darkedeneurope.com - Website WordPress vì mục đích cộng đồng.