前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >收集起来的一些常用的正则验证

收集起来的一些常用的正则验证

作者头像
wangxl
发布2018-03-07 15:33:54
4830
发布2018-03-07 15:33:54
举报
文章被收录于专栏:PHP在线PHP在线

class Regexp {

//put your code here

/**

* 验证真实姓名

*/

public static $realname = '/^[A-Za-z0-9\\u4e00-\\u9fa5]+$/';

/**

* 浮点数

*/

public static $decmal = "/^([+-]?)\\d*\\.\\d+$/";

/**

* 正浮点数

*/

public static $decmal1 = "/^[1-9]\\d*.\\d*|0.\\d*[1-9]\\d*$/";

/**

* 负浮点数

*/

public static $decmal2 = "/^-([1-9]\\d*.\\d*|0.\\d*[1-9]\\d*)$/";

/**

* 浮点数

*/

public static $decmal3 = "/^-?([1-9]\\d*.\\d*|0.\\d*[1-9]\\d*|0?.0+|0)$/";

/**

* 非负浮点数(正浮点数 + 0)

*/

public static $decmal4 = "/^[1-9]\\d*.\\d*|0.\\d*[1-9]\\d*|0?.0+|0$";

/**

* 非正浮点数(负浮点数 + 0)

*/

public static $decmal5 = "/^(-([1-9]\\d*.\\d*|0.\\d*[1-9]\\d*))|0?.0+|0$/";

/**

* 整数

*/

public static $intege = "/^-?[1-9]\\d*$/";

/**

* 正整数

*/

public static $intege1 = "/^[1-9]\\d*$/";

/*

* 负整数

*/

public static $intege2 = "/^-[1-9]\\d*$/";

/**

* 数字

*/

public static $num = "/^([+-]?)\\d*\\.?\\d+$/";

/**

* 正数(正整数 + 0)

*/

public static $num1 = "/^[1-9]\\d*|0$/";

/**

* 负数(负整数 + 0)

*/

public static $num2 = "/^-[1-9]\\d*|0$/";

/**

* 仅ACSII字符

*/

public static $ascii = "/^[\\x00-\\xFF]+$/";

/**

* 仅中文

*/

public static $chinese = "/^[\\u4e00-\\u9fa5]+$/";

/**

* 颜色

*/

public static $color = "/^[a-fA-F0-9]{6}$/";

/**

* 日期

*/

public static $date = "/^\\d{4}(\\-|\\/|\.)\\d{1,2}\\1\\d{1,2}$/";

/**

* 邮件

*/

public static $email = "/^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$/";

/**

* 身份证

*/

public static $idcard = "/^[1-9]([0-9]{14}|[0-9]{17})$/";

/**

* ip地址

*/

public static $ip4 = "/^(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)$/";

/**

* 字母

*/

public static $letter = "/^[A-Za-z]+$/";

/**

* 小写字母

*/

public static $letter_l = "/^[a-z]+$/";

/**

* 大写字母

*/

public static $letter_u = "/^[A-Z]+$/";

/**

* 手机

*/

public static $mobile = '/(13|15)[0-9]{9}$/';

/**

* 电话号

*/

public static $tel = "/(^(86)\-(0\d{2,3})\-(\d{7,8})\-(\d{1,4})$)|(^0(\d{2,3})\-(\d{7,8})$)|(^0(\d{2,3})\-(\d{7,8})\-(\d{1,4})$)|(^(86)\-(\d{3,4})\-(\d{7,8})$)/";

/**

* 非空

*/

public static $notempty = "/^\\S+$/";

/**

* 密码

*/

public static $password = "/^[A-Za-z0-9_-]+$/";

/**

* 图片

*/

public static $picture = "(.*)\\.(jpg|bmp|gif|ico|pcx|jpeg|tif|png|raw|tga)$/";

/*

* QQ号码

*/

public static $qq = "/^[1-9]*[1-9][0-9]*$/";

/**

* 压缩文件

*/

public static $rar = "(.*)\\.(rar|zip|7zip|tgz)$/";

/**

* url

*/

public static $url = "^http[s]? = \\/\\/([\\w-]+\\.)+[\\w-]+([\\w-./?%&=]*)?$/";

/**

* 用户名

*/

public static $username = "/^[A-Za-z0-9_\\-\\u4e00-\\u9fa5]+$/";

/**

* 邮编

*/

public static $zipcode = "/^\\d{6}$/";

}

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2015-06-14,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 php 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档