Skip to content

Commit

Permalink
v1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
albert-lii committed Aug 29, 2017
1 parent 727666d commit db5a559
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 6 deletions.
61 changes: 61 additions & 0 deletions sutils/src/main/java/com/liyi/sutils/constants/RegexConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.liyi.sutils.constants;

/**
* 常用正则表达式
*/

public class RegexConstants {
/**
* 正则:手机号(简单)
*/
public static final String REGEX_MOBILE_SIMPLE = "^[1]\\d{10}$";
/**
* 正则:手机号(精确)
* <p>移动:134(0-8)、135、136、137、138、139、147、150、151、152、157、158、159、178、182、183、184、187、188</p>
* <p>联通:130、131、132、145、155、156、171、175、176、185、186</p>
* <p>电信:133、153、173、177、180、181、189</p>
* <p>全球星:1349</p>
* <p>虚拟运营商:170</p>
*/
public static final String REGEX_MOBILE_EXACT = "^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,1,3,5-8])|(18[0-9])|(147))\\d{8}$";
/**
* 正则:电话号码
*/
public static final String REGEX_TEL = "^0\\d{2,3}[- ]?\\d{7,8}";
/**
* 正则:身份证号码15位
*/
public static final String REGEX_ID_CARD15 = "^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$";
/**
* 正则:身份证号码18位
*/
public static final String REGEX_ID_CARD18 = "^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9Xx])$";
/**
* 正则:邮箱
*/
public static final String REGEX_EMAIL = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
/**
* 正则:URL
*/
public static final String REGEX_URL = "[a-zA-z]+://[^\\s]*";
/**
* 正则:汉字
*/
public static final String REGEX_ZH = "^[\\u4e00-\\u9fa5]+$";
/**
* 正则:yyyy-MM-dd格式的日期校验,已考虑平闰年
*/
public static final String REGEX_DATE = "^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$";
/**
* 正则:IP地址
*/
public static final String REGEX_IP = "((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)";
/**
* 正则:中国邮政编码
*/
public static final String REGEX_ZIP_CODE = "[1-9]\\d{5}(?!\\d)";
/**
* 正则:用户名,取值范围为a-z,A-Z,0-9,"_",汉字,不能以"_"结尾,用户名必须是6-20位
*/
public static final String REGEX_USERNAME = "^[\\w\\u4e00-\\u9fa5]{6,20}(?<!_)$";
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package com.liyi.sutils;
package com.liyi.sutils.constants;



public final class SConstants {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import android.content.pm.PackageManager;
import android.support.annotation.NonNull;

import com.liyi.sutils.SConstants;
import com.liyi.sutils.constants.SConstants;
import com.liyi.sutils.utils.prompt.SLogUtil;

import java.security.MessageDigest;
Expand Down
19 changes: 19 additions & 0 deletions sutils/src/main/java/com/liyi/sutils/utils/common/SRegExUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.liyi.sutils.utils.common;

import android.support.annotation.NonNull;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* 正则表达式工具类
*/

public class SRegExUtil {

public static boolean compile(@NonNull String regEx, CharSequence value) {
Pattern pattern = Pattern.compile(regEx);
Matcher matcher = pattern.matcher(value);
return matcher.matches();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.bumptech.glide.TransitionOptions;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
import com.liyi.sutils.SConstants;
import com.liyi.sutils.constants.SConstants;
import com.liyi.sutils.utils.prompt.SLogUtil;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import android.support.annotation.NonNull;
import android.telephony.TelephonyManager;

import com.liyi.sutils.SConstants;
import com.liyi.sutils.constants.SConstants;
import com.liyi.sutils.utils.prompt.SLogUtil;

public class SNetUtil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import android.content.Context;
import android.text.TextUtils;

import com.liyi.sutils.SConstants;
import com.liyi.sutils.constants.SConstants;
import com.liyi.sutils.utils.prompt.SLogUtil;
import com.yanzhenjie.nohttp.rest.OnResponseListener;
import com.yanzhenjie.nohttp.rest.Response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import android.content.Context;

import com.liyi.sutils.R;
import com.liyi.sutils.SConstants;
import com.liyi.sutils.constants.SConstants;
import com.liyi.sutils.utils.prompt.SToastUtil;
import com.yanzhenjie.nohttp.error.NetworkError;
import com.yanzhenjie.nohttp.error.NotFoundCacheError;
Expand Down

0 comments on commit db5a559

Please sign in to comment.