How to determine if string is strictly decimal?

Asked

Viewed 78 times

0

I would like that if the string has the comma (as we use in the Brazilian real to represent the decimal places), it returns true and if not, return false.

Example:

"1" = false;
"1,00" = true;
"10" = false;
"10,00" = true;
"1000" = false;
"1.000,00" = true;
"10.000.000,56" = true;
"10000000,56" = false;
"10.000,00" = true;
"10000,00" = false;
"10.000.000.000,00" = true;
"10000000000,00" = false;
"1000000000000" = false;
"10000000000.00" = false;
"10,000,000,000,00" = false;

I’ve tried to do it this way, but it didn’t work:

bool valid = decimal.TryParse("1", NumberStyles.Currency, CultureInfo.GetCultureInfo("pt-BR"), out decimal r);

UPDATE:

I’m trying to validate from the regex here:

var regex = @"^-?(?:\d+|\d{1,3}(?:\.\d{3})+)(?:,\d+)[0-9\/]+?$";

var valor = "1000000000000";

var valid = Regex.Match(valor, regex, RegexOptions.IgnoreCase).Success ? true : false;

Some solution ?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.