参数检查

来源:互联网 发布:针织毛衣品牌推荐知乎 编辑:程序博客网 时间:2024/03/29 04:25

import java.math.BigDecimal;


public class CMNCMN0901U {
 /**
  * パラメータで渡された文字列の中にアルファベットの小文字が有れば、Trueを返す。
  * @return アルファベットの小文字が有ったか否かを返す
  * @param strInput 調べる対象の文字列
  */
 public static boolean containLowerCase(String strInput) {
  if (strInput == null) {
   throw new CMNCMN0325X("strInput", null);
  }
  boolean blnReturn = false;
  for (int i = 0; i < strInput.length(); i++) {
   char ch = strInput.charAt(i);
   if (ch >= 'a'  && ch <= 'z') {
    blnReturn = true;
    break;
   }else{
   }
  }
  return blnReturn;
 }
 /**
  * パラメータで渡された文字列の中にアルファベットの大文字が有れば、Trueを返す。
  * @return アルファベットの大文字が有ったか否かを返す。
  * @param strInput 調べる対象の文字列
  */
 public static boolean containUpperCase(String strInput) {
  if (strInput == null) {
   throw new CMNCMN0325X("strInput", null);
  }
  boolean blnReturn = false;
  for (int i = 0; i < strInput.length(); i++) {
   char ch = strInput.charAt(i);
   if (ch >= 'A'  && ch <= 'Z') {
    blnReturn = true;
    break;
   }
  }
  return blnReturn;
 }
 /**
  * パラメータで渡された文字列の中に英字以外の文字列が有れば、Falseを返す。
  * @return 英字以外の文字が有ったか否かを返す
  * @param strInput 調べる対象の文字列
  */
 public static boolean isAlpha(String strInput) {
  if (strInput == null) {
   throw new CMNCMN0325X("strInput", null);
  }
  boolean blnReturn = true;
  for (int i = 0; i < strInput.length(); i++) {
   char ch = strInput.charAt(i);
   if ((ch >= 'A'  && ch <= 'Z') ||
       (ch >= 'a'  && ch <= 'z')) {
   }else{
    blnReturn = false;
    break;
   }
  }
  return blnReturn;
 }
 /**
  * パラメータで渡された文字列の中に英数字以外の文字列が有れば、Falseを返す。
  * @return 英数字以外の文字が有ったか否かを返す
  * @param strInput 調べる対象の文字列
  */
 public static boolean isAlphaNum(String strInput) {
  if (strInput == null) {
   throw new CMNCMN0325X("strInput", null);
  }
  boolean blnReturn = true;
  for (int i = 0; i < strInput.length(); i++) {
   char ch = strInput.charAt(i);
   if ((ch >= '0'  && ch <= '9') ||
       (ch >= 'A'  && ch <= 'Z') ||
       (ch >= 'a'  && ch <= 'z')) {
   }else{
    blnReturn = false;
    break;
   }
  }
  return blnReturn;
 }
 
 /**
  * パラメータで渡された文字列の中に英数字以外の文字列が有れば、Falseを返す。
  * @return 英数字以外の文字が有ったか否かを返す
  * @param strInput 調べる対象の文字列
  */
 public static boolean isAlphaNumSpace(String strInput) {
  if (strInput == null) {
   throw new CMNCMN0325X("strInput", null);
  }
  boolean blnReturn = true;
  for (int i = 0; i < strInput.length(); i++) {
   char ch = strInput.charAt(i);
   if ((ch >= '0'  && ch <= '9') ||
       (ch >= 'A'  && ch <= 'Z') ||
       (ch >= 'a'  && ch <= 'z')   ||
       (ch == ' ')) {
   }else{
    blnReturn = false;
    break;
   }
  }
  return blnReturn;
 }
 
 /**
  * パラメータで渡された文字列の中に空白以外の文字列がある場合はFalseを返す。
  * @return 空白以外の文字が有ったか否かを返す。
  * @param strInput 調べる対象の文字列
  */
 public static boolean isBlank(String strInput) {
  if (strInput == null) {
   throw new CMNCMN0325X("strInput", null);
  }
  boolean blnReturn = true;
  for (int i = 0; i < strInput.length(); i++) {
   char ch = strInput.charAt(i);
   if (Character.isWhitespace(ch)) {
   }else{
    blnReturn = false;
    break;
   }
  }
  return blnReturn;
 }
 /**
  * パラメータで渡された文字列の中に数字以外の文字列が有れば、Falseを返す。
  * @return 数字以外の文字が有ったか否かを返す
  * @param strInput 調べる対象の文字列
  */
 public static boolean isNum(String strInput) {
  if (strInput == null) {
   throw new CMNCMN0325X("strInput", null);
  }
  boolean blnReturn = true;
  for (int i = 0; i < strInput.length(); i++) {
   char ch = strInput.charAt(i);
   if(ch >= '0'  && ch <= '9'){ 
   }else{
    blnReturn = false;
    break;
   }
  }
  return blnReturn;
 }


 /**
  * パラメータで渡された文字列が有効であるか否かを判定する。
  * @return 有効なとき、true、無効なときfalse
  * @param strInput 調べる対象の文字列
  * @param iLength  整数部の桁数
  * @param iScale   小数部の桁数
  */
 public static boolean isNum(String strInput, int iLength, int iScale) {

  if (strInput == null) {
   throw new CMNCMN0325X("strInput", null);
  }

        try {
       
            BigDecimal bdValue = new BigDecimal(strInput);

            // 小数点以下の桁数のチェック
            if (bdValue.scale() > iScale) {
                return false;
            } 

            // 整数部の桁数のチェック
            if (bdValue.compareTo(new BigDecimal(Math.pow(10, iLength))) < 0) {
                return true;
            } else {
                return false;
            }

        // 変換エラー時
        } catch (NumberFormatException ex) {
            return false;       
        }

 }

原创粉丝点击