分享一个非常全的php正则验证车牌格式的函数

 2023-09-13 阅读 25 评论 0

摘要:/** 判断是否合法车牌号* @name isCarLicense@author furong@param $license@return bool@since 2016年12月24日 11:51:22@abstract2017年4月7日 14:06:17 增加对 特种车牌,武警车牌,军牌的校验2018年3月5日 13:32:18 增加对 6位新能源车牌的

/**

  • 判断是否合法车牌号

*

  • @name isCarLicense
  • @author furong
  • @param $license
  • @return bool
  • @since 2016年12月24日 11:51:22
  • @abstract
  • 2017年4月7日 14:06:17 增加对 特种车牌,武警车牌,军牌的校验
  • 2018年3月5日 13:32:18 增加对 6位新能源车牌的校验

*/
function isCarLicense($license)
{

if (empty($license)) {return false;
}
#匹配民用车牌和使馆车牌
# 判断标准
# 1,第一位为汉字省份缩写
# 2,第二位为大写字母城市编码
# 3,后面是5位仅含字母和数字的组合
{$regular = "/[京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云渝藏陕甘青宁新使]{1}[A-Z]{1}[0-9a-zA-Z]{5}$/u";preg_match($regular, $license, $match);if (isset($match[0])) {return true;}
}#匹配特种车牌(挂,警,学,领,港,澳)
#参考 https://wenku.baidu.com/view/4573909a964bcf84b9d57bc5.html
{$regular = '/[京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云渝藏陕甘青宁新]{1}[A-Z]{1}[0-9a-zA-Z]{4}[挂警学领港澳]{1}$/u';preg_match($regular, $license, $match);if (isset($match[0])) {return true;}
}#匹配武警车牌
#参考 https://wenku.baidu.com/view/7fe0b333aaea998fcc220e48.html
{$regular = '/^WJ[京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云渝藏陕甘青宁新]?[0-9a-zA-Z]{5}$/ui';preg_match($regular, $license, $match);if (isset($match[0])) {return true;}
}#匹配军牌
#参考 http://auto.sina.com.cn/service/2013-05-03/18111149551.shtml
{$regular = "/[A-Z]{2}[0-9]{5}$/";preg_match($regular, $license, $match);if (isset($match[0])) {return true;}
}
#匹配新能源车辆6位车牌
#参考 https://baike.baidu.com/item/%E6%96%B0%E8%83%BD%E6%BA%90%E6%B1%BD%E8%BD%A6%E4%B8%93%E7%94%A8%E5%8F%B7%E7%89%8C
{#小型新能源车$regular = "/[京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云渝藏陕甘青宁新]{1}[A-Z]{1}[DF]{1}[0-9a-zA-Z]{5}$/u";preg_match($regular, $license, $match);if (isset($match[0])) {return true;}#大型新能源车$regular = "/[京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云渝藏陕甘青宁新]{1}[A-Z]{1}[0-9a-zA-Z]{5}[DF]{1}$/u";preg_match($regular, $license, $match);if (isset($match[0])) {return true;}
}
return false;

正则表达式邮箱的验证,}

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/3/55038.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息