zoukankan      html  css  js  c++  java
  • 车牌号验证正则验证

    /**
     *   判断是否合法车牌号
     *  @name isCarLicense
     *  @param $license 车牌号
     *  @return bool
     */
    public 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;
        }
        //匹配特种车牌(挂,警,学,领,港,澳)
        $regular = '/[京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云渝藏陕甘青宁新]{1}[A-Z]{1}[0-9a-zA-Z]{4}[挂警学领港澳]{1}$/u';
        preg_match($regular, $license, $match);
        if (isset($match[0]))
        {
            return true;
        }
        //匹配武警车牌
        $regular = '/^WJ[京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云渝藏陕甘青宁新]?[0-9a-zA-Z]{5}$/ui';
        preg_match($regular, $license, $match);
        if (isset($match[0]))
        {
            return true;
        }
        //匹配军牌
        $regular = "/[A-Z]{2}[0-9]{5}$/";
        preg_match($regular, $license, $match);
        if (isset($match[0]))
        {
            return true;
        }
        //匹配新能源车辆6位车牌
        //小型新能源车
        $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;
    }
  • 相关阅读:
    HTTP 错误 404.17
    ASP.NET 日志组件Smart.LogNet.DLL 引用即可写入日志及读取日志
    委托(Func与Action)
    三元表达式
    http://www.cnblogs.com/nangong/p/db29669e2c6d72fb3d0da947280aa1ce.htm ASP.NET从零开始学习EF的增删改查
    文件流的读写操作
    6.递归加载文件目录树(递归自己加载自己)
    文件基本操作
    线程
    委托
  • 原文地址:https://www.cnblogs.com/xiangangXu1997/p/12468917.html
Copyright © 2011-2022 走看看