You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
2.4 KiB

<?php
// 验证类
/**
* 检验手机号
* @param string $mobilehone 手机号
* @date 2021-01-22
*/
function isMobilephone($mobilehone = '')
{
$isMob = "/^1[3-9]{1}[0-9]{9}$/";
if (!preg_match($isMob, $mobilehone)) {
return false;
} else {
return true;
}
}
/**
* 检验是否是座机号
* @param string $seat_number 座机号
* @date 2021-01-22
*/
function isSeatNumber($seat_number = '')
{
$isTel = "/^([0-9]{3,4}-)?[0-9]{7,8}$/";
if (!preg_match($isTel, $seat_number)) {
return false;
} else {
return true;
}
}
/**
* 检验是否是座机号或是手机号
* @param string $phone 手机号或座机号
* @date 2021-01-22
*/
function isPhone($phone = '')
{
$isMob = "/^1[3-9]{1}[0-9]{9}$/";
$isTel = "/^([0-9]{3,4}-)?[0-9]{7,8}$/";
if (!preg_match($isMob, $phone) && !preg_match($isTel, $phone)) {
return false;
} else {
return true;
}
}
/**
* 检验身份证号
* @param string $vStr 身份证号
* @date 2021-01-22
*/
function isCreditNo($vStr)
{
$vCity = array(
'11', '12', '13', '14', '15', '21', '22',
'23', '31', '32', '33', '34', '35', '36',
'37', '41', '42', '43', '44', '45', '46',
'50', '51', '52', '53', '54', '61', '62',
'63', '64', '65', '71', '81', '82', '91'
);
if (!preg_match('/^([\d]{17}[xX\d]|[\d]{15})$/', $vStr))
return false;
if (!in_array(substr($vStr, 0, 2), $vCity))
return false;
$vStr = preg_replace('/[xX]$/i', 'a', $vStr);
$vLength = strlen($vStr);
if ($vLength == 18) {
$vBirthday = substr($vStr, 6, 4) . '-' . substr($vStr, 10, 2) . '-' . substr($vStr, 12, 2);
} else {
$vBirthday = '19' . substr($vStr, 6, 2) . '-' . substr($vStr, 8, 2) . '-' . substr($vStr, 10, 2);
}
if (date('Y-m-d', strtotime($vBirthday)) != $vBirthday)
return false;
if ($vLength == 18) {
$vSum = 0;
for ($i = 17; $i >= 0; $i--) {
$vSubStr = substr($vStr, 17 - $i, 1);
$vSum += (pow(2, $i) % 11) * (($vSubStr == 'a') ? 10 : intval($vSubStr, 11));
}
if ($vSum % 11 != 1)
return false;
}
return true;
}
/**
* 检验邮箱
* @param string $email 邮箱
* @date 2021-01-22
*/
function isEmail($email = '')
{
$mode = '/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/';
if (preg_match($mode, $email)) {
return true;
} else {
return false;
}
}