//验证电话
function checkPhone($phone)
{
$preg_mobile = preg_match("/^1\d{10}$/", $phone );
$preg_phone_city = preg_match("/^0\d{2}-?\d{8}$/", $phone );
$preg_phone_county = preg_match("/^0\d{3}-?\d{7}$/", $phone );
$preg_phone_general = preg_match("/^\d{7,8}$/", $phone );
if(($preg_mobile||$preg_phone_city||$preg_phone_county||$preg_phone_general))
{
return true;
}
return false;
}

ecshop电话验证

    if (!empty($office_phone) && !preg_match( '/^[\d|\_|\-|\s]+$/', $office_phone ) )
{
show_message($_LANG['passport_js']['office_phone_invalid']);
}
if (!empty($home_phone) && !preg_match( '/^[\d|\_|\-|\s]+$/', $home_phone) )
{
show_message($_LANG['passport_js']['home_phone_invalid']);
}

一个ecshop后台ajax修改电话的例子

<td align="center"><span onclick="listTable.edit(this, 'edit_phone', {$entity.id})">{$entity.phone}</span></td>
/*------------------------------------------------------ */
//-- 修改客户电话号码
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'edit_phone')
{
//check_authz_json('goods_manage'); $user_id = intval($_POST['id']);
$phone = $_POST['val']; if(!checkPhone($phone))
{//电话有误
make_json_error("手机格式不对");
}
$sql = "update c_users set phone='$phone' where id=$user_id";
if($db->query($sql)){
clear_cache_files();
make_json_result($phone);
}
}
05-11 22:20