后台校验类package plugin.back.validator /** ?*后台校验类 ?* ?* @author pc ?* ?*/ public class Part
后台校验类
package plugin.back.validator;
/**
?
*后台校验类
?*
?* @author pc
?*
?*/
public class PartBackValidator {
??? /**
????* 校验mail格式是否正确 true为正确 false为不正确
??? *
????* @param mail
??? * @return
????*/
??? publicstatic boolean validatorMail(String mail) {
???????String regex = "^[a-zA-Z0-9,~`!#$%^&·()-_=+|{};:'"<>/?\\.\\[\\]]{1,}@[0-9a-zA-Z\\.]{1,}\\.(com|cn|gov|net|com\\.cn|edu|int|mil|org|gmail)$";
???????if (mail.matches(regex)) {
???????????return true;
???????} else {
???????????return false;
???????}
??? }
??? ???// 校验半径 true为校验通过 false为校验失败
??
??? publicstatic boolean validatorRadius(String radius) {
???????String regex = "^[0-9]{1,}\\.[0-9]{1,}$";
???????String regexone = "^([0-9]{1,})$";
???????String regextwo = "^0{1,}\\.0{1,}$";
???????String regexthr = "^(0{1,})$";
???????if (radius.matches(regextwo) || radius.matches(regexthr)) {
???????????return false;
???????}
???????if (radius.matches(regex) || radius.matches(regexone)) {
???????????return true;
???????} else {
???????????return false;
???????}
??? }
?
????//校验某字符串是否超过指定的长度 true为是 false为否
?
??? publicstatic boolean validatorLength(String obj, int length) {
???????if (obj.getBytes().length > length) {
???????????return true;
???????} else {
???????????return false;
???????}
??? }
????//校验某对象是否为指定的类型 true为是 false为否
?
??? publicstatic boolean validatorType(Object obj, int type) {
???????switch (type) {
???????case 0:
???????????if (obj.getClass() == String.class) {
???????????????return true;
???????????} else {
???????????????return false;
???????????}
???????case 1:
???????????if (obj.getClass() == Integer.class) {
???????????????return true;
???????????} else {
???????????????return false;
???????????}
???????case 2:
???????????if (obj.getClass() == Float.class) {
???????????????return true;
???????????} else {
???????????????return false;
???????????}
???????default:
???????????return false;
???????}
??? }
???
????//校验用户名密码
?
??? publicstatic String validatorUserAndPassword(String userName, Stringpassword) {
???????StringBuffer buffer = new StringBuffer();
???????DataValidator validator = new DataValidator();
???????if ("".equals(userName) || "".equals(password)) {
???????????buffer.append("10"); // 传来的用户名密码为空
???????????return buffer.toString();
???????}
???????boolean flag = true;
???????try {
???????????flag = validator.isUser(userName, password);
???????} catch (Exception e) {
???????????buffer.append("11"); // 校验用户名密码时发生数据库连接错误
???????????return buffer.toString();
???????}
???????if (!flag) {
???????????buffer.append("00"); // 用户名密码错误
???????????return buffer.toString();
???????}
???????buffer.append("1A"); // 校验用户名密码通过
???????return buffer.toString();
??? }
??? //判断手机号码是否错误,true为正确
???
??? publicstatic boolean validatorPhone(String phone) {
???????String regex = "^[0-9]{11}";
???????if (phone.matches(regex)) {
???????????return true;
???????} else {
???????????return false;
???????}
??? }
??
????//校验是否为整数 true为是 false为否
??? publicstatic boolean validatorInteger(String inValue) {
???????String regex = "^([0-9]{1,})$";
???????if (inValue.matches(regex)) {
???????????return true;
???????} else {
???????????return false;
???????}
??? }
???
???// 校验是否为小数 true为是 false为否
??
??? publicstatic boolean validatorDouble(String doValue) {
???????String regex = "^([0-9]{1,})$";
???????String regexone = "^[0-9]{1,}\\.[0-9]{1,}$";
???????if (doValue.matches(regex) || doValue.matches(regexone)) {
???????????return true;
???????} else {
???????????return false;
???????}
??? }
}