//全角チェック
 public static boolean isFullWord(String i_strContents)
 {
  boolean value = true; 
  byte[] byteArray = null;
         byteArray = i_strContents.getBytes();
         for(int i = 0; i < byteArray.length; i++)
         {
             if((byteArray[i] >= (byte)0x81 && byteArray[i] <= (byte)0x9f) ||
                 (byteArray[i] >= (byte)0xe0 && byteArray[i] <= (byte)0xef))
             {
                 if((byteArray[i+1] >= (byte)0x40 && byteArray[i+1] <= (byte)0x7e) ||
                     (byteArray[i+1] >= (byte)0x80 && byteArray[i+1] <= (byte)0xfc))
                 {
                     i++;
                 }
                 else
                 {
                     value = false;
                 }
             }
             else
             {
                 value = false;
             }
         }
         return value;

 }
 //半角チェック
 public static boolean isHalfWord(String i_strContents)
 {
  boolean value = true;
  byte[] byteArray = null;
        byteArray = i_strContents.getBytes();
        for(int i = 0; i < byteArray.length; i++){
            if((byteArray[i] >= (byte)0x81 && byteArray[i] <= (byte)0x9f) ||
                (byteArray[i] >= (byte)0xe0 && byteArray[i] <= (byte)0xef)) {
                if((byteArray[i+1] >= (byte)0x40 && byteArray[i+1] <= (byte)0x7e) ||
                    (byteArray[i+1] >= (byte)0x80 && byteArray[i+1] <= (byte)0xfc)) {
                    value = true;
                }
            }
        }
        return value;

 }

  //名前の全角を検査します。
 public static boolean checkNameFormat(String i_strContents)
 {
  boolean bResult = (!i_strContents.equals("")&&Validation.isFullWord(i_strContents));
  return bResult;
 }

 //点数と人数の半角を検査します
 public static boolean checkPointFormat(String i_strContents)
 {
  boolean bResult = true;
  int iContents;

  //半角の時
  if(!i_strContents.equals("")&&!Validation.isFullWord(i_strContents))
  {
   iContents = Integer.parseInt(i_strContents);
   //0点から100点以内
   if((iContents < 0) || (iContents > 100))
   {
    bResult = false;
   }
  }
  else
  {
   bResult = false;
  }
  return bResult;
 
 }
Validation 체크시 전각을하던 반각을 하던 위의 하나의 메소드를 이용하여 true이면 false로 구분하여
사용하면 한개의 메소드로도 충분히 구현이 가능함

##다른방법으로 전각을 체크하는거

 //全角チェック
 public static boolean isFullWord2(String i_strContents)
 {
  boolean value = true;
  //入力もらた文字の長さ
  for (int i = 0; i < i_strContents.length(); ++i)
  {
         //文字を一つ一つチェックします
   int c = i_strContents.charAt(i);       
   //全角の条件
   if (c < 256 || (c >= 0xff61 && c <= 0xff9f))
         {
           value = false;
         }
      }
      return value;
 }

+ Recent posts