Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

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

, 12 Sep 2011
Rate this:
Please Sign up or sign in to vote.
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:
 
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)

About the Author

Daaron
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... PinmemberDrABELL13-Sep-11 3:06 
GeneralYutz? Careful, your ego is showing... PinmemberChunkyStool12-Sep-11 15:27 
GeneralWhat a yutz. That's why they call it an alternative. PinmemberDaaron12-Sep-11 12:19 
GeneralRe: thanks for your contribution, PinmemberAria Wijaya12-Sep-11 14:57 
GeneralReason for my vote of 2 This alternative does not work for s... PinmemberChunkyStool12-Sep-11 11:44 
GeneralRe: thank you for pointing out the limitation, great stuff PinmemberAria Wijaya12-Sep-11 14:58 

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 12 Sep 2011
Article Copyright 2011 by Daaron
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid