Java validating strings for digits
The following three different formats are demonstrated The first regular expression allows one or more characters in the set [0-9] preceded or followed by any number of spaces within the length of the string.
Yet, a developer may have an occasion where accepting formatted currency is required.
Is Match to validate that a string is either empty, or exactly 4 characters (digits) in length.
Is Match to validate that a string is either empty, or exactly 4 characters (digits) in length. Is Match(str, "[0-9]^4")) return true; but this does not work. Is Match("1234", @"\d\d\d\d") come close, but also result in "12345" validating.
After that there can be zero or more groups composed of a comma and exactly three digits.
It ends with an optional group composed of a decimal and two digits.
These were, however, still strings since the results of any mathimatical operation using them is meaningless. Numerical data is alway handled as string representations of numbers in (X)HTML forms or when the data is sent to the server.