package com.mandi.common.ParamFileter;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.mandi.dao.common.ObjectResult;
/**
* 正则表达式验证
* 2016年4月10日 下午4:37:21
* @author guolq
*/
public class RegexCheck {
/**
* checkphone:验证手机号码11位
* @param phone
* @return
* TODO
*/
public static boolean checkphone(String phone){
boolean flag = false;
if(phone==null||phone.trim().isEmpty())
return flag;
try{
Pattern p = Pattern.compile("^[1][0-9]{10}$"); //^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$
Matcher m = p.matcher(phone);
flag = m.matches();
}catch(Exception e){
flag = false;
}
return flag;
}
/**
* checkempty:字符串不能为空和null
* @param strargs
* @return
* TODO
*/
public static boolean checkempty(String...strargs){
for (String str : strargs) {
if (str==null||str.trim().isEmpty()) {
return false;
}
}
return true;
}
public static String checkempty(T obj,String[][] fieldandname){
StringBuffer bf=new StringBuffer();
if(obj==null)
{
bf.append("对象不存在!");
return bf.toString();
}
@SuppressWarnings("rawtypes")
Class cls=obj.getClass();
try {
if(fieldandname==null||fieldandname[0].length<=0)
return bf.toString();
for(int i=0;i T copyobj(T reobj,T orobj,String[] fiedsName){
if(reobj==null)
return null;
if(orobj==null||fiedsName==null||fiedsName.length<=0)
return reobj;
@SuppressWarnings("rawtypes")
Class recls=reobj.getClass();
@SuppressWarnings("rawtypes")
Class orcls=orobj.getClass();
for(int i=0;i Map ObjtoMap(T Obj,String[] fiedsName){
Map mp=new HashMap();
if(Obj==null)
return mp;
@SuppressWarnings("rawtypes")
Class recls=Obj.getClass();
if(fiedsName==null||fiedsName.length<=0){
Field[] ff=recls.getFields();
for (int i = 0; i < ff.length; i++) {
// mp.put(, );
}
}else
{
for(int i=0;i checkpassword(String pwd,String oldpwd){
ObjectResult objresult =new ObjectResult();
try {
if(oldpwd==null||pwd==null||oldpwd.trim().isEmpty()||pwd.trim().isEmpty()){
objresult.setCode(1);
objresult.setHint("密码不能设置为空");
objresult.setItem(false);
return objresult;
}
//pwd=pwd.replaceAll("\\s*|\t|\r|\n| | |", "").replaceAll(" | ", "");//去除字符串中所包含的空格(包括:空格(半角)、制表符、换页符等)
Pattern p = Pattern.compile("(?!^\\d+$)(?!^[a-zA-Z]+$).{6,16}");
Matcher m = p.matcher(pwd);
boolean boo = m.matches();
if(boo){
objresult.setCode(0);
objresult.setHint(pwd);
objresult.setItem(boo);
}else{
objresult.setCode(1);
objresult.setHint("密码格式必须包含:字母和数字(可以包含特殊字符)的6到16位的字符串");
objresult.setItem(boo);
}
} catch (Exception e) {
objresult.setCode(1);
objresult.setHint("密码检验出错,请重新输入密码!!");
}
return objresult;
}
/**
* getsearchwords:简单处理分割一些搜索词
* @param shword
* @return
* TODO
*/
public static String getsearchwords(String shword){
if (shword==null||shword.trim().isEmpty())
return null;
if (shword.length()>200) {
shword=shword.substring(0, 200);//200个字符
}
shword=shword.replaceAll(" |,|,|,| | ", " ");//替换一些特殊字符
shword=shword.replaceAll(" {2,}", " ");
String[] strs=shword.trim().split(" ");
if (strs==null)
return null;
StringBuffer strbuf=new StringBuffer();
for (int i =0; i