Share a PHP verification class, check whether the input is a number, check whether the input is a phone number, check whether the input is a mobile phone number, check whether the input is a zip code, email address legality check, name and nickname legality check , you can only enter Chinese and English to check whether an (English) domain name is legal.
First download the PHP verification class library we need to use in this course: http://www.php.cn/xiazai/leiku/778
After the download is complete, find what we need php class file, unzip it to our local directory, and create a new php file!
After completion, we need to call this class in the new php file and instantiate the class:
<?php include_once "code1.php";//引入类文件 $obj = new Validator; //实例化类 //输入值 进行验证 符合要求返回 1 echo "检查输入的是否为数字:".$obj->isNumber('123456')."<br>"; echo "检查日期是否符合:".$obj->isTime("2017-08-18 14:02:30")."<br>"; echo "检查输入值是否为合法人民币格式:".$obj->isMoney("325")."<br>"; echo "检查输入IP是否符合要求:".$obj->isIp("127.0.0.1")."<br>"; echo "检查日期是否符合:".$obj->isDate("2017-08-18")."<br>"; echo "检查是否输入为汉字:".$obj->isChinese("合肥的中文网")."<br>"; echo "检查是否输入为英文:".$obj->isEnglish("www.php.cn")."<br>"; echo "检查字符串长度是否符合要求:".$obj->isEngLength("zww","2","120")."<br>"; echo "姓名昵称合法性检查,只能输入中文英文:".$obj->isName("zww")."<br>"; ?>
Run this file and get the result as shown below:
##
The above is the detailed content of Example analysis of PHP implementation of various data verification. For more information, please follow other related articles on the PHP Chinese website!