正则表达式
来源:互联网 发布:飞鸟p2p网络理财 编辑:程序博客网 时间:2024/05/22 16:02
1、连续6位数字的验证码
Pattern pattern=Pattern.compile("(\\d{6})"); Matcher matcher=pattern.matcher(body); if (matcher.find()){ code = matcher.group(0); }
public static boolean isNull(EditText editText) { String text = editText.getText().toString().trim(); if (text != null && text.length() > 0) { return false; } return true; } /** * 账号校验 * * @param text * @账号长度为6-18位 */ public static boolean matchAccount(String text) { if (Pattern.compile("^[a-z0-9_-]{5,18}$").matcher(text).matches()) { return true; } return false; } /** * Ip地址校验 * * @param ip * @return */ public static boolean matchIpAddress(String ip) { Pattern pa = Pattern .compile("^(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])$"); Matcher ma = pa.matcher(ip); boolean b = ma.matches(); return b; } /** * 手机号码校验 * * @param text * @return */ public static boolean matchPhoneno(String text) { Pattern p = Pattern .compile("^((1[3,5,8][0-9])|(14[5,7])|(17[0,6,7,8]))//d{8$}"); // /(^1[3|4|5|7|8][0-9]{9}$)/; Matcher m = p.matcher(text); return m.matches(); } public static boolean isMobileNO(String mobiles) { // Pattern p = // Pattern.compile("^((13[0-9])|(15[^4,\\D])|(17[0-9])|(18[0,5-9]))\\d{8}$"); Pattern p = Pattern.compile("^1[3|4|5|7|8][0-9]{9}$"); Matcher m = p.matcher(mobiles); // logger.info(m.matches()+"---"); return m.matches(); } /** * 校验网关编号 * @param gatewayno * @return */ public static boolean isGatewayNO(String gatewayno) { Pattern p = Pattern.compile("^[0-9]{16}$"); //长度为16的数字串 Matcher m = p.matcher(gatewayno); return m.matches(); } /** * 邮箱校验 * * @param text * @return */ public static boolean matchEmail(String text) { if (Pattern.compile("\\w[\\w.-]*@[\\w.]+\\.\\w+").matcher(text) .matches()) { return true; } return false; } public static boolean isEmail(String email) { String str = "^([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)*@([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)+[\\.][A-Za-z]{2,3}([\\.][A-Za-z]{2})?$"; Pattern p = Pattern.compile(str); Matcher m = p.matcher(email); // logger.info(m.matches()+"---"); return m.matches(); } /** * is null or its length is 0 * * <pre> * isEmpty(null) = true; * isEmpty("") = true; * isEmpty(" ") = false; * </pre> * * @param str str * @return if string is null or its size is 0, return true, else return * false. */ public static boolean isEmpty(CharSequence str) { return (str == null || str.length() == 0); }
0 0
- 【正则表达式】正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- NBUT1025-IP地址
- 如何使用组合命令(Compound Command)
- 使用参数化查询防止SQL注入漏洞
- NSThread
- 一兆到底是什么?
- 正则表达式
- sublime text2安装package control以及docblockr插件
- 间接转子磁场定向
- C程序—>可执行程序的过程
- CNN训练技巧
- eclipse创建动态web项目
- Delete Node in a Linked List
- mysql使用bind_param()参数绑定来防止SQL注入攻击
- WP-Optimize插件定期自动清理和优化数据库