Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check whether a string is a (very big) number?

I need to make a number validation for specified string. The problem is, the string could be a large number, larger than any numeric type in C# can represent, so I can't use TryParse functions, because they will give only information about whether they can convert to those types.

It should take into account -/+, separator, and current culture settings.

I found some solutions using regular expressions, but all of them miss some details. And I'm not good at regular expressions

like image 394
username Avatar asked Dec 16 '22 20:12

username


1 Answers

You can use BigInteger if you are using C# 4.0 and the numbers are integers.

It Represents an arbitrarily large signed integer.

Use the TryParse method to avoid the possible exception from Parse (unless you are certain that the passed in string will always be a valid integer).

like image 134
Oded Avatar answered Jan 15 '23 23:01

Oded