JAVA 正则表达式

来源:互联网 发布:服务器端口设置 编辑:程序博客网 时间:2024/06/05 00:38


//至少两个汉字
"^[\u4e00-\u9fa5a]{2,}$"搜索
//手机号
^1[0-9]{10}$


 /** Comment for method 验证手机号码 */
public static boolean isMobileNO(String mobiles) {
Pattern p = Pattern.compile("^(13|14|15|18)[0-9]{9}$");
Matcher m = p.matcher(mobiles);
return m.matches();
}

/** Comment for method 验证邮箱 */
public static boolean isEmail(String strEmail) {
String strPattern = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
Pattern p = Pattern.compile(strPattern);
Matcher m = p.matcher(strEmail);
return m.matches();



  String regex = "^([\\w-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([\\w-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
String mail = mail_content.getText().toString().trim();// 邮箱

 if (!mail.matches(regex)) {}


验证输入密码长度 (6-18位)
String regex = "^\\d{6,18}$";

验证输入身份证号
String regex = "(^\\d{18}$)|(^\\d{15}$)";

http://www.cnblogs.com/silentjesse/p/3242701.html



0 0
原创粉丝点击