You are here

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

4 posts / 0 new
Last post
Amit G
Offline
Last seen: 15 years 4 months ago
Joined: 2007-07-30 10:22
I need to know how to validate data in VC# using ASCII code?

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.

John Bentley
John Bentley's picture
Offline
Last seen: 15 years 4 months ago
Developer
Joined: 2006-01-24 13:26
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.'

Amit G
Offline
Last seen: 15 years 4 months ago
Joined: 2007-07-30 10:22
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 = 65 && c[i] = 97 && c[i]

John Bentley
John Bentley's picture
Offline
Last seen: 15 years 4 months ago
Developer
Joined: 2006-01-24 13:26
Don't use break. e.Cancel =

Don't use break.

e.Cancel = true;

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

Log in or register to post comments