private String validateCellvalue(String strCellvalue, int iKey) throws Exception {
if(iKey == 0&&UtilityFunction.isBlank(strCellvalue)){
this.isvalidateOK = false;
return "<font color=red>Merchant Trans ID is missing.</font>";
}else if (iKey == 1 && UtilityFunction.isBlank(strCellvalue)) {
this.isvalidateOK = false;
return "<font color=red>First Name is missing.</font>";
} else {
return strCellvalue;
}
                            }
这里已经判断了Merchant id和name是否为空了,为空就报错误消息。现在想多判断(& + \) 这个2个标点符号,如果有就报错误消息。不知道如何判断?请教各位。在线等大家

解决方案 »

  1.   

    public static boolean isInt(String string) {
    boolean flag = false;
    if (!((string == null) && (string.trim().length() == 0))) {
    if (string.matches("[0-9]+")) {
    flag = true;
    }
    }
    return flag;
    }是像判断是否数字这样,先写个方法是否那2个标点符号,然后再判断吧?
      

  2.   

    其实在后面继续加else if就好了,但我觉得呢,开始判断的改成以为空做为条件,然后在里面进行iKey的判断会更好些。简写代码如下:(不一定对,只供参考)private String validateCellvalue(String strCellvalue, int iKey) throws Exception { 
      if (UtilityFunction.isBlank(strCellvalue)) {
          if (iKey == 0) {
             this.isvalidateOK = false;
             return " <font color=red>Merchant Trans ID is missing. </font>"; 
         } else if (iKey == 1) {
             this.isvalidateOK = false;
             return " <font color=red>First Name is missing. </font>";
         }
     }
      else {
          if (XXXX) {
        }
         return strCellvalue;
     }
    }
      

  3.   

    接着else{}里面写     else {
            if (strCellvalue.indexOf('&') > 0) {
               return "Error message";
            }
            if (strCellvalue.indexOf('\') > 0) {
               return "Error message";
            }
         return strCellvalue;
      }
    我写的不一定对,你需要测试下
      

  4.   

    if(strCellvalue.indexOf("\\")!=-1||strCellvalue.indexOf("& ")!=-1){
     return "你输入中含有\和&这两个特殊字符";
    }