1

Windows Phone 7 にテキスト ボックスがあります。ユーザーが入力した通常の文字、特殊文字、または ASCII を検証したいと考えています。

4

4 に答える 4

2

次のようにして、押されたキーが文字、数字、または特殊文字であるかどうかを判断できます。

private void textBox1_KeyPress(object sender, KeyEventArgs e)
{
  if (Char.IsLetter(e.KeyChar))
  {
    // The character is a letter
  }
  else if (Char.IsDigit(e.KeyChar))
  {
    // The character is a digit
  }
  else
  {
    // The character is a special character
  }
}
于 2012-07-14T08:15:11.327 に答える
1

私はこのようにしました..

public int CountChars(string value)
        {
            int result = 0;
            foreach (char c in value)
            {
              if (c>127)
                {
                    result = result + 10; // For Special Non ASCII Codes Like "ABCÀßĆʣʤʥ"
                }

                else
                {
                    result++; // For Normal Characters Like "ABC"
                }
            }
            return result;
        }
于 2012-07-14T09:49:48.723 に答える
0

この関数を使用して、textBox 内のテキストに関するデータを取得できます。

 private void validator(string value, out int letterCount, out int digitCount, out int specialCharCount)
        {
            letterCount=digitCount=specialCharCount=0;
            foreach (char c in value)
            {
                if (Char.IsLetter(c))
                    letterCount++;
                else if (Char.IsDigit(c))
                    digitCount++;
                else
                    specialCharCount++;

            }
        }

次のように呼び出します。

 int a, b, c;
 validator(textBox1.Text, out a, out b, out c);

textBox1 はあなたのテキストボックスです。値を入力し、a,b,cこれらの値を使用して、必要に応じて計算を実行できます。

于 2012-07-14T16:18:20.523 に答える
0

マスク付きのマスクテキストボックスを簡単に使用してください!!!

于 2012-07-14T07:45:13.447 に答える