zoukankan      html  css  js  c++  java
  • RE validator

    package com.office.utility;
     
    import java.util.regex.Pattern;
     
    /**
     * 校验器:利用正则表达式校验邮箱、手机号等
     *
     * @author liujiduo
     *
     */
    public class Validator {
        /**
         * 正则表达式:验证用户名
         */
        public static final String REGEX_USERNAME = "^[a-zA-Z]\w{5,17}$";
        /**
         * 正则表达式:验证密码
         */
        public static final String REGEX_PASSWORD = "^[a-zA-Z0-9]{6,16}$";
     
        /**
         * 正则表达式:验证手机号
         */
        public static final String REGEX_MOBILE = "^((13[0-9])|(15[^4,\D])|(18[0,5-9]))\d{8}$";
     
        /**
         * 正则表达式:验证邮箱
         */
        public static final String REGEX_EMAIL = "^([a-z0-9A-Z]+[-|\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\.)+[a-zA-Z]{2,}$";
    /**
         * 校验用户名
         *
         * @param username
         * @return 校验通过返回true,否则返回false
         */
        public static boolean isUsername(String username) {
            return Pattern.matches(REGEX_USERNAME, username);
        }
     
        /**
         * 校验密码
         *
         * @param password
         * @return 校验通过返回true,否则返回false
         */
        public static boolean isPassword(String password) {
            return Pattern.matches(REGEX_PASSWORD, password);
        }
     
        /**
         * 校验手机号
         *
         * @param mobile
         * @return 校验通过返回true,否则返回false
         */
        public static boolean isMobile(String mobile) {
            return Pattern.matches(REGEX_MOBILE, mobile);
        }
     
        /**
         * 校验邮箱
         *
         * @param email
         * @return 校验通过返回true,否则返回false
         */
        public static boolean isEmail(String email) {
            return Pattern.matches(REGEX_EMAIL, email);
        }
     
    --------------------------------
    转自:https://www.oschina.net/code/snippet_1021818_47946
  • 相关阅读:
    c#自动更新+安装程序的制作
    VS2013项目受源代码管理向源代码管理注册此项目时出错
    WinDbg配置和使用基础
    InstallShield Limited Edition for Visual Studio 2013 图文教程(教你如何打包.NET程序)
    PowerDesigner 如何生成数据库更新脚本
    用户故事(User Story)
    Troubleshooting Record and Playback issues in Coded UI Test
    Coded UI
    compare two oracle database schemas
    How to: Use Schema Compare to Compare Different Database Definitions
  • 原文地址:https://www.cnblogs.com/ydc198/p/10590729.html
Copyright © 2011-2022 走看看