I have textbox in my windows phone 7. I want to validate that user input normal character or some special character or ASCII.
Asked
Active
Viewed 2,838 times
1
-
can please give me an example of your expectation in words – HatSoft Jul 14 '12 at 09:12
-
Yeah Sure. One Min Let Me Do It For You.. – Arslan Pervaiz Jul 14 '12 at 09:15
-
http://www.asciitable.com/ Here see extended ASCII Codes from 128 code to 175.. – Arslan Pervaiz Jul 14 '12 at 09:22
4 Answers
2
You can determine if the key that is pressed is a letter, digit, or special character by doing the following:
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
}
}

A. Abiri
- 10,750
- 4
- 30
- 31
-
-
If you're wondering on how to determine ascii vs. unicode, then chibacity's answer to this question might help you: http://stackoverflow.com/questions/4459571/how-to-recognize-if-a-string-contains-unicode-chars – A. Abiri Jul 14 '12 at 18:45
-
I have already done that and put my answer as well. Thanks again :) – Arslan Pervaiz Jul 14 '12 at 19:52
1
I have done in this way..
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;
}

Arslan Pervaiz
- 1,575
- 4
- 29
- 62
0
simple use a mask text box with a mask!!!

Abadis
- 2,671
- 5
- 28
- 42
-
visual studio has a controler called masked text box.read here =>http://www.codeproject.com/Articles/1534/Masked-C-TextBox-Control – Abadis Jul 14 '12 at 08:03
-
Oups You Are Totally Going In Wrong Direction. I Am Talking About Windows Phone 7 Perceptive. Not Web or Windows Form Base Application. Thanks – Arslan Pervaiz Jul 14 '12 at 08:06
0
You can use this function to get data about the text in the 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++;
}
}
Call it as:
int a, b, c;
validator(textBox1.Text, out a, out b, out c);
textBox1 is your textBox. It will populate the values of a,b,c
and using these values you can perform calculations as you desire.

naqvitalha
- 793
- 5
- 9