Home  >  Article  >  Backend Development  >  Determine whether it is a legal zip code (fixed length) in PHP_PHP tutorial

Determine whether it is a legal zip code (fixed length) in PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 16:59:49992browse

The purpose of this function is to determine whether it is a legal zip code (fixed length). The method is very simple, just use regular expressions to operate.

The code is as follows
 代码如下 复制代码


< ?php

// 函数名:CheckPost($C_post)

// 作 用:判断是否为合法邮编(固定长度)

// 参 数:$C_post(待check的邮政编码)

// 返回值:布尔值

// 备 注:无

//-----------------------------------------------------------------------------------

function CheckPost($C_post)

{

$C_post=trim($C_post);

if (strlen($C_post) == 6)

{

if(!ereg("^[+]?[_0-9]*$",$C_post))

{

return true;;

}else

{

return false;

}

}else

{

return false;;

}

}

?>

Copy code

< ?php

// Function name: CheckPost($C_post)

// Parameter: $C_post (postal code to be checked) //Return value: Boolean value // Remarks: None //--------------------------------------------- ----------------------------------------

function CheckPost($C_post)
{<🎜> <🎜>$C_post=trim($C_post);<🎜> <🎜>if (strlen($C_post) == 6)<🎜> <🎜>{<🎜> <🎜>if(!ereg("^[+]?[_0-9]*$",$C_post))<🎜> <🎜>{<🎜> <🎜>return true;;<🎜> <🎜>}else<🎜> <🎜>{<🎜> <🎜>return false;<🎜> <🎜>}<🎜> <🎜>}else<🎜> <🎜>{<🎜> <🎜>return false;;<🎜> <🎜>}<🎜> <🎜>}<🎜> <🎜>?> http://www.bkjia.com/PHPjc/631297.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631297.htmlTechArticleThe function of this function is to determine whether it is a legal zip code (fixed length). The method is very simple, just use regular expressions to operate. The code is as follows Copy code ?php // Function name: CheckPost($C_post) // Function...
Statement:
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
Previous article:PHP user login code session, cookie automatic memory function_PHP tutorialNext article:PHP user login code session, cookie automatic memory function_PHP tutorial

Related articles

See more