Android开发中常用字符处理工具类
发布时间:2020-05-24 18:35:50 所属栏目:Java 来源:互联网
导读:Android开发中常用字符处理工具类
|
下面是脚本之家 jb51.cc 通过网络收集整理的代码片段。 脚本之家小编现在分享给大家,也给大家做个参考。 public class VerifyTool {
/*
* 邮箱验证
*/
public static boolean isEmail(String email) {
return Pattern.compile("^w+((-w+)|(.w+))*@[A-Za-z0-9]+((.|-)[A-Za-z0-9]+)*.[A-Za-z0-9]+$").matcher(email).matches();
}
/**
* 验证密码格式,只支持英文和数字.
*
*/
public static boolean verifyPasswordFormat(String pwd) {
return Pattern.compile("[a-zA-Z0-9]*").matcher(pwd).matches();
}
/**
*
* @description:验证手机号是否正确(这是根据我们项目需要进行的,实际的不一定都这样)
*/
public static boolean isMobileNO(String telephone) {
if (TextUtils.isEmpty(telephone))
return false;
// Pattern pattern = Pattern.compile("^0?(13[0-9]|15[012356789]|17[012356789]|18[012356789]|14[57])[0-9]{8}$");
Pattern pattern = Pattern.compile("^1[3,4,5,7,8][0-9]d{8}$");
Matcher matcher = pattern.matcher(telephone);
return matcher.matches();
}
/**
* 验证电话号码及是否正确;
*
*/
public static boolean isPhoneNO(String mobiles) {
Pattern p = Pattern.compile("^d{10,12}$");
Matcher m = p.matcher(mobiles);
return m.matches();
}
/**
* 验证6位短信验证码是否正确;
*
*/
public static boolean isSmsCode(String msgCode) {
Pattern p = Pattern.compile("^d{6}$");
Matcher m = p.matcher(msgCode);
return m.matches();
}
/**
* 验证IP和端口的格式是否有误
*
* @param ip
* 访问服务器 IP 地址
* @param port
* 访问服务器端口
* @return 校验ip和端口 return -1 ip 或者 port 为空. -2 ip格式错误. -3 port为数字 0 通过
* */
public static final int verificateIPAndPort(String ip,String port) {
if (null == ip || "".equals(ip) || null == port || "".equals(port)) {
return -1;
}
try {
Integer.parseInt(port);
}
catch (NumberFormatException e) {
return -3;
}
Pattern pattern = Pattern.compile("b((?!ddd)d+|1dd|2[0-4]d|25[0-5]).((?!ddd)d+|1dd|2[0-4]d|25[0-5]).((?!ddd)d+|1dd|2[0-4]d|25[0-5]).((?!ddd)d+|1dd|2[0-4]d|25[0-5])b");
Matcher matcher = pattern.matcher(ip.trim());
if (matcher.matches()) {
return 0;
}
else {
return -2;
}
}
/**
*
* 方法概述:
*
* @description 方法详细描述:验证输入的金额为整数且只能有两个位小数
*/
public static boolean monneyFormate(String s) {
if (TextUtils.isEmpty(s))
return false;
Pattern pattern = Pattern.compile("^(-)?(([1-9]{1}d*)|([0]{1}))(.(d){1,2})?$");
return pattern.matcher(s).matches();
}
/**
* (判断字符串的长度)
*/
public static boolean isCheckLength(String str,int start,int end) {
Pattern pattern = Pattern.compile("^.{" + start + "," + end + "}$");
return pattern.matcher(str).matches();
}
/**
* @author:tsp
* @Title: isLength
* @Description: TODO(判断身份证的长度)
* @param @param str
* @param @return
* @return boolean
* @throws
*/
public static boolean isCheckCardLenth(String str,int end) {
Pattern pattern = Pattern.compile("^[A-Za-z0-9].{" + start + "," + end + "}$");
return pattern.matcher(str).matches();
}
/**
*
* @description:判断是否是身份证格式
*/
public static boolean checkCardNo(String cardNo) {
Pattern pattern = Pattern.compile("(^d{15}$)|(^d{18}$)|(^d{17}(d|X|x)$)");
Matcher matcher = pattern.matcher(cardNo);
return matcher.matches();
}
/**
* 判断中文
*/
public static boolean isChineseChar(String inputString) {
Pattern pattern = Pattern.compile("^[u4E00-u9FA5uF900-uFA2D]+$");
// Pattern pattern = Pattern.compile("^[u4E00-u9FA5]");
return pattern.matcher(inputString).matches();
}
/**
* 匹配非负浮点数
*/
public static boolean isRealNumber(String inputString) {
Pattern pattern = Pattern.compile("^[0-9]+(.[0-9]{1,5})?$");
return pattern.matcher(inputString).matches();
}
/**
* 匹配非负浮点数
*/
public static boolean isNotNegativeFloat(String inputString) {
Pattern pattern = Pattern.compile("^[1-9]d*.d*|0.d*[1-9]d*|0?.0+|0$");
return pattern.matcher(inputString).matches();
}
/**
* 手机号码截取成130****123类型字段,因为用之前方式 的话,诸如17999999990类似号码会截取成:17********0
*/
public static String splitePhone(String phone) {
String[] tel = new String[phone.length()];
StringBuffer sb = new StringBuffer();
if (tel.length > 0) {
for (int i = 0; i < tel.length; i++) {
if (i > 2 && i < 7) {
sb.append("*");
} else {
sb.append(phone.charAt(i));
}
}
}
return sb.toString();
}
}
以上是脚本之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。 如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
