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;
}
}
}
*
* @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;
}
}
}
相关推荐
校验框架包、校验的注解、使用实例。校验框架包、校验的注解、使用实例。
后台通过注解的方式对model 的值进行校验。判断值是否符合类型要求或长度要求。
NULL 博文链接:https://lsz1023-126-com.iteye.com/blog/2072312
NULL 博文链接:https://huhongyu.iteye.com/blog/1757258
通过用户登录的例子,用Struts2的validator做后台的校验
使用注解的形式校验前端参数的正确性,使代码更简洁,专心处理业务逻辑,将校验规则解耦到了validate校验器中,要项目源码的私聊我
.net实体类字段校验,通过Attribute属性自定义校验、及错误信息。可校验字段长度,字段类型通过校验函数校验,统一校验 [TypeCheck(Name = "", Message = "请选择开始时间", Validate = ValidateUtils._DateTime)] ...
ASP.NET Core5.0 WebApi和BlazorWebAssembly 博客后台管理系统(jwt登录校验)MySQL数据库
本文主要分享了PHP登录(ajax提交数据和后台校验)的实例代码,具有一定的参考价值,下面跟着小编一起来看下吧
简单的登录校验, 我也是初学者 可以供大家看看,为了积分
银行卡号正确性校验,支持所有银行卡号。符合Luhm校验
用EXTJS做的登陆验证,完整源码~后台是asp.
有关手势设置 手势验证 app前后台监控的android demo
hibernate后台数据校验所需要的三个完整jar包,三个jar包需要一起使用,版本号要对应。
具体代码如下所示: <!DOCTYPE html> <html lang=en> <head> <meta charset=UTF-8> <...--此处model的abc 要是下面input 绑定的对象名称, ref 要和提交按钮的submit参数
CRC即循环冗余校验码(Cyclic Redundancy Check [1] ):是数据通信领域中最常用的一种查错校验码,其特征是信息字段和校验字段的长度可以任意选定。循环冗余检查(CRC)是一种数据传输检错功能,对数据进行多项式...
代码演示了几种获取MimeType类型的方法,包括jar包
重复发票校验的防止,需要前后台都进行设定。已经经过测试,方法是有效的。
主要给大家介绍了关于ASP.NET全栈开发教程之前后台校验结合的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
提供代码生成工具类,可一键生成所需的基本代码,生成的代码模版中增删改查功能直接可用。 二. 使用步骤 2.1).下载后解压。导入项目。 2.2).执行init中的sql。主要是要把系统用户建立起来。 2.3).运行项目,前台...