表单中文本框中数据合法性的检查

来源:互联网 发布:mac win7虚拟机下载 编辑:程序博客网 时间:2024/05/21 06:44

表单中文本框中数据合法性的检查:
1.文本框必须入力检查
public boolean isBlank(String input)
{
  if(input == null)
  {
    return false;
  }
  if(input.trim().length() == 0)
  {
    return false;
  }
  return true;
}
2.半角文字检查
public static boolean isOnlyhalf(String input)
{
  if(input == null)
  {
    return false;
  }
  try{
    if(!input.equals(""))
    {
       byte[] byteArray = input.getBytes("MS932")
       int strLength = input.length();
       if(!(strLength == byteArray.length))
       {
          return false;
       }
    }
  }
  catch(UnSupportedEncodingException e){
    return false;
  }
return true;
}
3.许容文字检查(半角文字)
public boolean checkAllowValueofHalf(char inout,String[] allowChars)
{
  boolean blnRet =false;
  if(allowChars == null)
  {
     return false;
  }
  int allowCharSize = allowChars.length;
  for(int j = 0;j < allowCharSize;j++)
  {
    if(isOnlyHalf)
    {
      if(allowChars[j].length == 1)
      {
           if(allowChars[j].charAt(0) == input)
           {
              blnRet = true;
              break;
           }
           else
           {
              continue;
           }
       else
        {
           continue;
        }     

      }
    }
  }
return blnRet;
}

原创粉丝点击