2013年2月7日星期四

Android手机、E-mail、QQ验证



   /**
     * 验证字符串是否是email
     * @param str
     * @return
     */
    public static boolean isEmail(String str) {
Pattern pattern = Pattern.compile("[//w//.//-]+@([//w//-]+//.)+[//w//-]+",Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(str);
if (matcher.matches()) {
return true;
}else {
return false;
}
}  

    /**
     * 验证是否是手机号码
     * @param str
     * @return
     */
    public static boolean isCellphone(String str) {
Pattern pattern = Pattern.compile("1[0-9]{10}");
Matcher matcher = pattern.matcher(str);
if (matcher.matches()) {
return true;
}else {
return false;
}
}

    /**
     * 验证是否是QQ号码
     * @param str
     * @return
     */
    public static boolean isQQ(String str) {
Pattern pattern = Pattern.compile("[1-9]{5,10}");
Matcher matcher = pattern.matcher(str);
if (matcher.matches()) {
return true;
}else {
return false;
}
}
分享到:
上一篇

没有评论:

发表评论