Get the new PortableApps.com Platform 10.0: Gorgeous themes, a full portable app store and advanced functionality
Announcing the World's Best Flash Drive: The PortableApps.com Companion | Did you see a malware warning on Friday?

I need to know how to validate data in VC# using ASCII code?

Amit G - February 10, 2009 - 6:15am

I have three text boxes in which data has to be inserted and then via ADO.NET stored in SQL database,the three text boxes are Customer First Name,Customer Last Name and Contact Number,thus using ASCII code one has to restrict data that only alphabets are accepted in the first two text boxes and numbers in the third text box,there should also be a restriction so as to see that the maximum number of digits in the third text box is limited to 12 or 11,actually this was the work of my team member but he has run off leaving me in a fix,I am not too comfortable with this and it's become a huge problem,please do let me know what coding needs to be done to ensure this type of restriction and validation.


( categories: )

Use a regular expression for

Use a regular expression for the first two. (http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.r...) You can use int.TryParse to determine if it is an integer. (double.TryParse for a double) for the limited digits use textBox.Text.Length.

cowsay Moo
cowthink 'Dude, why are you staring at me.'

What is wrong with this code? it's in VC#

I have tried the initial validation and it worked just right and I am left with the ASCII part as of now so I coded something which just isn't working,what's wrong with this code?

private void textBox1_Validating(object sender, CancelEventArgs e)
{
string s = textBox1.Text;
char[] c = s.ToCharArray();
for (int i = 0; i < c.Length; i++)
{
if ((c[i] >= 65 && c[i] <= 90) || (c[i] >= 97 && c[i] <= 122) || (c[i] == 32))
b = true;
else
{
MessageBox.Show("You Can Enter Alphabets Only,Numbers and Special Characters Not Allowed");
textBox1.Text = "";
textBox1.Focus();
break;
}
}
}
My Application is almost complete,if I get the right code for this and it works,then it's just creating the setup and everything else is hunky dory.

Don't use break. e.Cancel =

Don't use break.

e.Cancel = true;

cowsay Moo
cowthink 'Dude, why are you staring at me.'