/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.hwj.util;
/**
*
* @author hwj
*/
public class StringUtil {
public static boolean validateNull(String s) {
if (s == "" || s.length() == 0) {
return false;
} else {
return true;
}
}
//2 数字格式
public static boolean validateDigit(String s) {
//验证数字
String regex = "^(\\d+)|(\\d+\\.\\d+)$";
if (s.matches(regex)) {
return true;
} else {
return false;
}
}
public static boolean Length(String s) {
if (s.length() > 10) {
return false;
} else {
return true;
}
}
public static boolean isEmail(String s) {
String regex = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
if (s.matches(regex)) {
return true;
} else {
return false;
}
}
public static boolean isPhone(String s){
String regex="^(((13[0-9])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8})|(0\\d{2}-\\d{8})|(0\\d{3}-\\d{7})$";
if(s.matches(regex)){
return true;
}else{
return false;
}
}
// public static void main(String args[]) {
// String s = "[email protected]";
// String phone="1358373533";
// boolean test = isEmail(s);
// boolean t=isPhone(phone);
// System.out.println("邮箱:"+test);
// System.out.println("phone:"+t);
// }
}
变量regex为正则表达式