该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
刚开始只是想检验一下输入的是不是中文,后来学了正则表达式后,想尝试一下,把常见的姓氏通过字符串判断的形式,主要是对姓氏进行验证,当然还有输入长度,可我对自己写得东西,有点不伦不类了。对于有些名字,它能通过。而有些就不行了。当然,姓氏都在程序的列表(聚类)中。我想仅仅是用一个自定义的函数来实现,因为仅仅是判断,应用的实际价值也不大。不想复杂化,请各位大哥指点,万分感激!
//以下是程序部分(仅仅是一种思路),注释框中的部分我分别试过。
function checkname()
{
global $common_name;
if(!preg_match("/^[".chr(0xa1)."-".chr(0xff)."]+$/",$common_name))
{
die("");
}
/* if(
!preg_match("/^((李)|(王)|(张)|(刘)|(陈)|(杨)|(赵)|(黄)|(周)|(吴)|(徐)|(孙)|(胡)|(朱)|(高)|(林)|(何)|(郭)|(马)|(罗)|(梁)|(宋)|(郑)|(谢)|(韩)|(唐)|(冯)|(于)|(董)|(萧)|(程)|(曹)|(袁)|(邓)|(许)|(傅)|(沈)|(曾)|(彭)|(吕)|(苏)|(卢)|(蒋)|(蔡)|(贾)|(丁)|(魏)|(薛)|(叶)|(阎)|(余)|(潘)|(杜)|(戴)|(夏)|(钟)|(汪)|(田)|(任)|(姜)|(范)|(方)|(石)|(姚)|(谭)|(廖)|(邹)|(熊)|(金)|(陆)|(郝)|(孔)|(白)|(崔)|(康)|(毛)|(邱)|(秦)|(江)|(史)|(顾)|(侯)|(邵)|(孟)|(龙)|(万)|(段)|(章)|(钱)|(汤)|(尹)|(黎)|(易)|(常)|(武)|(乔)|(贺)|(赖)|(龚)|(文))+$/",$common_name))
{
die("");
}
*/
/*elseif(
!preg_match("/^['李'-'王'-'张'-'刘'-'陈'-'杨'-'赵'-'黄'-'周'-'吴'-'徐'-'孙'-'胡'-'朱'-'高'-'林'-'何'-'郭'-'马'-'罗'-'梁'-'宋'-'郑'-'谢'-'韩'-'唐'-'冯'-'于'-'董'-'萧'-'程'-'曹'-'袁'-'邓'-'许'-'傅'-'沈'-'曾'-'彭'-'吕'-'苏'-'卢'-'蒋'-'蔡'-'贾'-'丁'-'魏'-'薛'-'叶'-'阎'-'余'-'潘'-'杜'-'戴'-'夏'-'钟'-'汪'-'田'-'任'-'姜'-'范'-'方'-'石'-'姚'-'谭'-'廖'-'邹'-'熊'-'金'-'陆'-'郝'-'孔'-'白'-'崔'-'康'-'毛'-'邱'-'秦'-'江'-'史'-'顾'-'侯'-'邵'-'孟'-'龙'-'万'-'段'-'章'-'钱'-'汤'-'尹'-'黎'-'易'-'常'-'武'-'乔'-'贺'-'赖'-'龚'-'文']+*$/",$common_name))
{
die("");
}*/
if(strlen($common_name)>6||strlen($common_name)<4)
{
die("");
}
}