Home > Backend Development > PHP Tutorial > How to use regular rules to determine whether it is a mobile phone number in php

How to use regular rules to determine whether it is a mobile phone number in php

墨辰丷
Release: 2023-03-25 20:30:02
Original
9549 people have browsed it

This article mainly introduces how to use regular expressions in php to determine whether it is a mobile phone number. Interested friends can refer to it. I hope it will be helpful to everyone.

The code is as follows:

$phonenumber = '13712345678';
if(preg_match("/^1[34578]{1}\d{9}$/",$phonenumber)){
    echo "是手机号码";
}else{
    echo "不是手机号码";
}
Copy after login


"^" matches the beginning of the text, and "$" matches the end of the text.

Related recommendations:

##PHP regular matching date and time (timestamp conversion) Example code

PHP regular expression to verify email address

php regular expression only retains Chinese alphanumeric characters

The above is the detailed content of How to use regular rules to determine whether it is a mobile phone number in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template