I am trying to create a method that can process and check integers, as in ok input. The problem lies in our requirements, in which the following numbers are entered as ok, regardless of the language chosen:
1500, 1.500, 1,500, 1 500 -1500, -1.500, -1,500, -1 500 1500000, 1.500.500, 1,500,500 1 500 500 -1500000, -1.500.500, -1,500,500 -1 500 500
etc.
Now my method is as follows:
private bool TryParseInteger(string controlValue, out int controlInt) { int number; NumberStyles styles = NumberStyles.Integer | NumberStyles.AllowThousands; bool result = Int32.TryParse(controlValue, styles, CultureInfo.InvariantCulture, out number); controlInt = number; return result; }
This does not work as I want. 1.500 and 1.500.500 are not checked as the correct input.
Is there any other way to approach this?
Thanks for the help. As it turned out, 1,500.50 (etc.) should not be tested, because of which the proposed solutions do not work. Any other ideas?
user3351548
source share