Home > php教程 > php手册 > 简单的几个验证函数

简单的几个验证函数

WBOY
Release: 2016-06-06 19:35:54
Original
1195 people have browsed it

利用简单的正则做的电话号码的验证 无 ?php//用来验证手机号码function checkMobil($string=''){ $pattern = "/^[1]\d{10}$/"; if(preg_match($pattern, $string)){ return TRUE; }else{ return FALSE; }} $mobil = '13510066807';$result = checkMobil($mobi

利用简单的正则做的电话号码的验证
<?php

//用来验证手机号码
function checkMobil($string=''){
    $pattern = "/^[1]\d{10}$/";
    if(preg_match($pattern, $string)){
        return TRUE;
    }else{
        return FALSE;
    }
}
 
$mobil = '13510066807';
$result = checkMobil($mobil);
var_dump($result);//TRUE;
 
 
//用来验证座机号码
function checkPhone($string=''){
    $pattern = "/^(\d{3,4}-)\d{7,8}$/";
    if(preg_match($pattern, $string)) return TRUE;
    else return FALSE;
}
$phone = '0755-6661027';
$result = checkPhone($phone);
var_dump($result);//TRUE;
 
//用来验证电子邮箱号码
function checkEmail($string=''){
    $pattern="/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i";
    if(preg_match($pattern, $string)) return TRUE;
    else return FALSE;
}
$email = 'asdfasdf23@gmail.com';
$resutl = checkEmail($email);
var_dump($result);//TRUE;


Copy after login
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template