Click here to Skip to main content
11,567,922 members (40,768 online)
Click here to Skip to main content

Tagged as

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

, 15 Sep 2011 CPOL 3.8K 1
Rate this:
Please Sign up or sign in to vote.
The alternative posted by Daaron does not work for several cases. E.g. Sign is included (+ or -), text contains whitespace prefix or suffix, etc. You could fix the first two limitations with a more detailed regex like "(^\s*(-|\+)?\d+\s*$)" but you could still end up with a value that won't fit...

The alternative posted by Daaron does not work for several cases. E.g. Sign is included (+ or -), text contains whitespace prefix or suffix, etc. You could fix the first two limitations with a more detailed regex like "(^\s*(-|\+)?\d+\s*$)" but you could still end up with a value that won't fit in type 'int'. IMHO, int.TryParse is the best way to validate.

License

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

Share

About the Author

ChunkyStool
Software Developer Insight Global
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralReason for my vote of 5 Indeed, I prefer int.TryParse over a... Pin
KenBonny13-Sep-11 20:31
memberKenBonny13-Sep-11 20:31 

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 | Terms of Use | Mobile
Web04 | 2.8.150624.2 | Last Updated 15 Sep 2011
Article Copyright 2011 by ChunkyStool
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid