Click here to Skip to main content
15,886,199 members
Articles / Programming Languages / C#
Alternative
Tip/Trick

Validate numeric textbox using int.tryparse visual C#.NET

Rate me:
Please Sign up or sign in to vote.
3.67/5 (3 votes)
12 Sep 2011CPOL 14.5K   6
You could do the same thing with a regular expression:if (Regex.Replace(textBox1.Text, @"\D", "") == textBox1.Text){textBox2.Text = ("tryparse method succeed");} else { textBox2.Text=("value entered is not numeric"); }
You could do the same thing with a regular expression:

C#
if (Regex.Replace(textBox1.Text, @"\D", "") == textBox1.Text)
{
textBox2.Text = ("tryparse method succeed");
} else { textBox2.Text=("value entered is not numeric"); }

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
Raised by wolves in the mean streets of Macintosh C/C++ for IBM and Motorola, moved on to Delphi and now C#. Ah, the mother's milk of Microsoft...

Comments and Discussions

 
GeneralReason for my vote of 4 Validation should be performed first... Pin
DrABELL13-Sep-11 3:06
DrABELL13-Sep-11 3:06 
GeneralYutz? Careful, your ego is showing... Pin
ChunkyStool12-Sep-11 15:27
ChunkyStool12-Sep-11 15:27 
GeneralWhat a yutz. That's why they call it an alternative. Pin
Daaron12-Sep-11 12:19
Daaron12-Sep-11 12:19 
GeneralRe: thanks for your contribution, Pin
Aria Wijaya12-Sep-11 14:57
Aria Wijaya12-Sep-11 14:57 
GeneralReason for my vote of 2 This alternative does not work for s... Pin
ChunkyStool12-Sep-11 11:44
ChunkyStool12-Sep-11 11:44 
GeneralRe: thank you for pointing out the limitation, great stuff Pin
Aria Wijaya12-Sep-11 14:58
Aria Wijaya12-Sep-11 14:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.