Exemple #1
0
        /// <summary>チェック前の変換処理</summary>
        public void PreValidate()
        {
            // 生入力
            string txt = this.Text2;

            // 半角指定(マスクで指定できないため)
            if (this.EditToHankaku)
            {
                // ワーク
                string        temp = "";
                StringBuilder sb   = new StringBuilder();

                // 半角化する。
                temp = Public.Str.StringConverter.ToHankaku(txt);

                // 残っている全角文字を削る。
                foreach (char ch in temp)
                {
                    if (StringChecker.IsHankaku(ch.ToString()))
                    {
                        // 半角だけ追加する。
                        sb.Append(ch);
                    }
                }

                if (txt != sb.ToString())
                {
                    // 変更された場合は再設定
                    txt       = sb.ToString();
                    base.Text = txt;
                }
            }

            // YYYYMMDDのM、Dが1桁の時に補正処理を行う。
            if (this.EditToYYYYMMDD)
            {
                if (Public.Str.StringConverter.EditYYYYMMDDString(ref txt))
                {
                    // 変更された場合は再設定
                    base.Text = txt;
                }
            }
        }
Exemple #2
0
        /// <summary>チェック処理</summary>
        /// <param name="result">結果文字列</param>
        /// <returns>
        /// ・エラーなし:true
        /// ・エラーあり:false
        /// </returns>
        /// <remarks>
        /// マスク前の値をチェックする
        /// ・必須入力チェック
        /// ・数値チェック
        ///
        /// マスク後の値をチェックする
        /// ・半角チェック
        /// ・全角チェック
        /// ・片仮名チェック
        /// ・半角片仮名チェック
        /// ・平仮名チェック
        /// ・日付チェック
        /// ・正規表現チェック
        /// ・禁則文字チェック
        /// </remarks>
        public bool Validate(out string[] result)
        {
            // フラグ
            bool hasError = false;
            // ワーク
            List <string> lstRet = new List <string>();

            // 生入力
            string text = this.Text2;
            // 編集中
            string editingText = "";
            // 編集後
            string editedText = "";

            // 編集中・編集後
            this.GetTexts(out editingText, out editedText);

            if (this.CheckType != null)
            {
                // 必須入力チェック
                if (this.CheckType.IsIndispensabile)
                {
                    if ((text == ""))
                    {
                        hasError = true;
                        lstRet.Add(CmnCheckFunction.IsIndispensabileCheckErrorMessage);
                    }
                }

                // 数値チェック(空文字列は対象外)
                if (this.CheckType.IsNumeric && text.Trim() != "")
                {
                    if (!StringChecker.IsNumeric(text))
                    {
                        hasError = true;
                        lstRet.Add(CmnCheckFunction.IsNumericCheckErrorMessage);
                    }
                }

                // 半角チェック
                if (this.CheckType.IsHankaku)
                {
                    if (!StringChecker.IsHankaku(text))
                    {
                        hasError = true;
                        lstRet.Add(CmnCheckFunction.IsHankakuCheckErrorMessage);
                    }
                }

                // 全角チェック
                if (this.CheckType.IsZenkaku)
                {
                    if (!StringChecker.IsZenkaku(text))
                    {
                        hasError = true;
                        lstRet.Add(CmnCheckFunction.IsZenkakuCheckErrorMessage);
                    }
                }

                // 片仮名チェック
                if (this.CheckType.IsKatakana)
                {
                    if (!StringChecker.IsKatakana(text))
                    {
                        hasError = true;
                        lstRet.Add(CmnCheckFunction.IsKatakanaCheckErrorMessage);
                    }
                }

                // 半角片仮名チェック
                if (this.CheckType.IsHanKatakana)
                {
                    if (!StringChecker.IsKatakana_Hankaku(text))
                    {
                        hasError = true;
                        lstRet.Add(CmnCheckFunction.IsHanKatakanaCheckErrorMessage);
                    }
                }

                // 平仮名チェック
                if (this.CheckType.IsHiragana)
                {
                    if (!StringChecker.IsHiragana(text))
                    {
                        hasError = true;
                        lstRet.Add(CmnCheckFunction.IsHiraganaCheckErrorMessage);
                    }
                }

                // 日付チェック(空文字列は対象外)
                if (this.CheckType.IsDate && text.Trim() != "")
                {
                    // 編集後を使用してチェック
                    // 編集中・編集後(再取得)
                    this.GetTexts(out editingText, out editedText);

                    DateTime dateTime;
                    if (!DateTime.TryParse(editedText, out dateTime) ||
                        text.IndexOfAny(new char[] { ' ', ' ' }) != -1)
                    {
                        hasError = true;
                        lstRet.Add(CmnCheckFunction.IsDateCheckErrorMessage);
                    }
                }
            }

            // 正規表現チェック(空文字列は対象外)
            if (this.CheckRegExp != null && this.CheckRegExp != "" && text.Trim() != "")
            {
                if (!StringChecker.Match(text, this.CheckRegExp))
                {
                    hasError = true;
                    lstRet.Add(CmnCheckFunction.RegularExpressionCheckErrorMessage);
                }
            }

            // 禁則文字チェック
            if (this.CheckProhibitedChar)
            {
                foreach (char ch in CmnCheckFunction.ProhibitedChars)
                {
                    if (text.IndexOf(ch) != -1)
                    {
                        hasError = true;
                        lstRet.Add(CmnCheckFunction.ProhibitedCharsCheckErrorMessage);
                        break;
                    }
                }
            }

            // 背景変更
            if (hasError)
            {
                // エラーの背景色
                if (this._backupBkColor == null)
                {
                    this._backupBkColor = (Color?)this.BackColor;
                    this.BackColor      = Color.Red;
                }
            }
            else
            {
                // 正常時の背景色
                if (this._backupBkColor != null)
                {
                    this.BackColor      = (Color)this._backupBkColor;
                    this._backupBkColor = null;
                }
            }

            result = lstRet.ToArray();
            return(!hasError);
        }
        /// <summary>チェック処理</summary>
        /// <param name="result">結果文字列</param>
        /// <returns>
        /// ・エラーなし:true
        /// ・エラーあり:false
        /// </returns>
        /// <remarks>
        /// ・必須入力チェック
        /// ・数値チェック
        /// ・半角チェック
        /// ・全角チェック
        /// ・片仮名チェック
        /// ・半角片仮名チェック
        /// ・平仮名チェック
        /// ・日付チェック
        ///
        /// ・正規表現チェック
        /// ・禁則文字チェック
        /// </remarks>
        public bool Validate(out string[] result)
        {
            // フラグ
            bool hasError = false;
            // ワーク
            List <string> lstRet = new List <string>();

            string text = this.Text;

            if (this.CheckType != null)
            {
                // 必須入力チェック
                if (this.CheckType.Required)
                {
                    if ((text == ""))
                    {
                        hasError = true;
                        lstRet.Add(CmnCheckFunction.RequiredCheckErrorMessage);
                    }
                }

                // 数値チェック(空文字列は対象外)
                if (this.CheckType.IsNumeric && text.Trim() != "")
                {
                    if (!StringChecker.IsNumeric(text))
                    {
                        hasError = true;
                        lstRet.Add(CmnCheckFunction.IsNumericCheckErrorMessage);
                    }
                }

                // 半角チェック
                if (this.CheckType.IsHankaku)
                {
                    if (!StringChecker.IsHankaku(text))
                    {
                        hasError = true;
                        lstRet.Add(CmnCheckFunction.IsHankakuCheckErrorMessage);
                    }
                }

                // 全角チェック
                if (this.CheckType.IsZenkaku)
                {
                    if (!StringChecker.IsZenkaku(text))
                    {
                        hasError = true;
                        lstRet.Add(CmnCheckFunction.IsZenkakuCheckErrorMessage);
                    }
                }

                // 片仮名チェック
                if (this.CheckType.IsKatakana)
                {
                    if (!StringChecker.IsKatakana(text))
                    {
                        hasError = true;
                        lstRet.Add(CmnCheckFunction.IsKatakanaCheckErrorMessage);
                    }
                }

                // 半角片仮名チェック
                if (this.CheckType.IsHanKatakana)
                {
                    if (!StringChecker.IsKatakana_Hankaku(text))
                    {
                        hasError = true;
                        lstRet.Add(CmnCheckFunction.IsHanKatakanaCheckErrorMessage);
                    }
                }

                // 平仮名チェック
                if (this.CheckType.IsHiragana)
                {
                    if (!StringChecker.IsHiragana(text))
                    {
                        hasError = true;
                        lstRet.Add(CmnCheckFunction.IsHiraganaCheckErrorMessage);
                    }
                }

                // 日付チェック(空文字列は対象外)
                if (this.CheckType.IsDate && text.Trim() != "")
                {
                    DateTime dateTime;
                    if (!DateTime.TryParse(text, out dateTime))
                    {
                        hasError = true;
                        lstRet.Add(CmnCheckFunction.IsDateCheckErrorMessage);
                    }
                }
            }

            // 正規表現チェック(空文字列は対象外)
            if (this.CheckRegExp != null && this.CheckRegExp != "" && text.Trim() != "")
            {
                if (!StringChecker.Match(text, this.CheckRegExp))
                {
                    hasError = true;
                    lstRet.Add(CmnCheckFunction.RegularExpressionCheckErrorMessage);
                }
            }

            // 禁則文字チェック
            if (this.CheckProhibitedChar)
            {
                foreach (char ch in CmnCheckFunction.ProhibitedChars)
                {
                    if (text.IndexOf(ch) != -1)
                    {
                        hasError = true;
                        lstRet.Add(CmnCheckFunction.ProhibitedCharsCheckErrorMessage);
                        break;
                    }
                }
            }

            // 背景変更
            if (hasError)
            {
                // エラーの背景色
                if (this.ViewState["wcc_backupBkColor"] == null)
                {
                    this.ViewState["wcc_backupBkColor"] = (Color?)this.BackColor;
                    this.BackColor = Color.Red;
                }
            }
            else
            {
                // 正常時の背景色
                if (this.ViewState["wcc_backupBkColor"] != null)
                {
                    this.BackColor = (Color)this.ViewState["wcc_backupBkColor"];
                    this.ViewState["wcc_backupBkColor"] = null;
                }
            }

            result = lstRet.ToArray();
            return(!hasError);
        }
Exemple #4
0
        public static void IsHankakuTest(string input, bool result)
        {
            bool output = StringChecker.IsHankaku(input);

            Assert.AreEqual(output, result);
        }