java校验电话号码/座机格式处理工具

public static String checkPhone(String phone) {
		String empty = "empty";
		String format_error = "formatError";
		String right = "right";

		if (null == phone || "".equalsIgnoreCase(phone)) {

			return empty;
		} else {
			if (phone.length() != 11) {
				return format_error;
			}
			String regex = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9])|(16[6]))\\d{8}$";
			// String regex1 = "/0\\d{2,3}-\\d{7,8}/";座机
			Pattern p = Pattern.compile(regex);
			Matcher m = p.matcher(phone);
			boolean isMatch = m.matches();
			if (!isMatch) {
				return format_error;
			}
		}
		return right;
	}

你可能感兴趣的:(工具)