参数检查

本文介绍了一系列用于验证字符串的方法,包括检查字符串是否包含小写字母、大写字母、数字、空白字符等,同时提供了验证字符串是否为纯英文、纯数字或英数字组合的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;       
        }

 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值