Results 1 to 2 of 2

Thread: To validate an integer ..

  1. #1

    Thread Starter
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437

    To validate an integer ..

    is Double.TryParse a better way or use Regular Expression, and why ?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: To validate an integer ..

    Double.TryParse performs the conversion for you, rather than just telling you whether a conversion is possible. Having said that, it will produce a Double that must still be cobverted to an Integer. Also, TryParse allows you to easily specify the types of numbers that are valid where a regular expression would start to get quite complex. .NET 2.0 has a TryParse method for every numeric type. Finally, using a TryParse method is more self-documenting than using a Regex, which is a more generic operation and you'd have to examine the pattern itself to see exactly what it was doing. In the grand scheme of things I doubt that there's much difference, but TryParse is more specific to the task so I would use it for that reason alone.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width