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

前端之家收集整理的这篇文章主要介绍了分享一个非常全的正则验证车牌格式的函数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. /**
  2. * 判断是否合法车牌号
  3. *
  4. * @name isCarLicense
  5. * @access public
  6. * @author furong
  7. * @param $license
  8. * @return bool
  9. * @since 2016年12月24日 11:51:22
  10. * @abstract
  11. * 2017年4月7日 14:06:17 增加对 特种车牌,武警车牌,军牌的校验
  12. *
  13. */
  14. function isCarLicense($license)
  15. {
  16. if (empty($license)) {
  17. return false;
  18. }
  19. #匹配民用车牌和使馆车牌
  20. # 判断标准
  21. # 1,第一位为汉字省份缩写
  22. # 2,第二位为大写字母城市编码
  23. # 3,后面是5位仅含字母和数字的组合
  24. {
  25. $regular = "/[京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云渝藏陕甘青宁新使]{1}[A-Z]{1}[0-9a-zA-Z]{5}$/u";
  26. preg_match($regular,$license,$match);
  27. if (isset($match[0])) {
  28. return true;
  29. }
  30. }
  31.  
  32. #匹配特种车牌(挂,警,学,领,港,澳)
  33. #参考 https://wenku.baidu.com/view/4573909a964bcf84b9d57bc5.html
  34. {
  35. $regular = '/[京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云渝藏陕甘青宁新]{1}[A-Z]{1}[0-9a-zA-Z]{4}[挂警学领港澳]{1}$/u';
  36. preg_match($regular,$match);
  37. if (isset($match[0])) {
  38. return true;
  39. }
  40. }
  41.  
  42. #匹配武警车牌
  43. #参考 https://wenku.baidu.com/view/7fe0b333aaea998fcc220e48.html
  44. {
  45. $regular = '/^WJ[京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云渝藏陕甘青宁新]?[0-9a-zA-Z]{5}$/ui';
  46. preg_match($regular,$match);
  47. if (isset($match[0])) {
  48. return true;
  49. }
  50. }
  51.  
  52. #匹配军牌
  53. #参考 http://auto.sina.com.cn/service/2013-05-03/18111149551.shtml
  54. {
  55. $regular = "/[A-Z]{2}[0-9]{5}$/";
  56. preg_match($regular,$match);
  57. if (isset($match[0])) {
  58. return true;
  59. }
  60. }
  61. return false;
  62. }

猜你在找的正则表达式相关文章