国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home php教程 php手冊(cè) php不用正則驗(yàn)證真*

php不用正則驗(yàn)證真*

Jun 13, 2016 am 09:31 AM

直接看代碼吧,很簡(jiǎn)單的一個(gè)PHP類

復(fù)制代碼 代碼如下:


$IDCard = new IDCard();
var_dump($IDCard::isCard($_GET['card']));

/**
?* 身份證處理類
?*/
class IDCard {

??? //檢證身份證是否正確
??? public static function isCard($card) {
??????? $card = self::to18Card($card);
??????? if (strlen($card) != 18) {
??????????? return false;
??????? }

??????? $cardBase = substr($card, 0, 17);

??????? return (self::getVerifyNum($cardBase) == strtoupper(substr($card, 17, 1)));
??? }

?
??? //格式化15位身份證號(hào)碼為18位
??? public static function to18Card($card) {
??????? $card = trim($card);

??????? if (strlen($card) == 18) {
??????????? return $card;
??????? }

??????? if (strlen($card) != 15) {
??????????? return false;
??????? }

??????? // 如果身份證順序碼是996 997 998 999,這些是為百歲以上老人的特殊編碼
??????? if (array_search(substr($card, 12, 3), array('996', '997', '998', '999')) !== false) {
??????????? $card = substr($card, 0, 6) . '18' . substr($card, 6, 9);
??????? } else {
??????????? $card = substr($card, 0, 6) . '19' . substr($card, 6, 9);
??????? }
??????? $card = $card . self::getVerifyNum($card);
??????? return $card;
??? }

??? // 計(jì)算身份證校驗(yàn)碼,根據(jù)國家標(biāo)準(zhǔn)gb 11643-1999
??? private static function getVerifyNum($cardBase) {
??????? if (strlen($cardBase) != 17) {
??????????? return false;
??????? }
??????? // 加權(quán)因子
??????? $factor = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);

??????? // 校驗(yàn)碼對(duì)應(yīng)值
??????? $verify_number_list = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');

??????? $checksum = 0;
??????? for ($i = 0; $i ??????????? $checksum += substr($cardBase, $i, 1) * $factor[$i];
??????? }

??????? $mod = $checksum % 11;
??????? $verify_number = $verify_number_list[$mod];

??????? return $verify_number;
??? }
}
?


?>
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

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)