I have a regex that will validate to make sure I have a number. but it passed if the string I'm checking is "" as well. how can I make a "" fail?
^(\\d|-)?(\\d|,)*\\.?\\d*$
I have a regex that will validate to make sure I have a number. but it passed if the string I'm checking is "" as well. how can I make a "" fail?
^(\\d|-)?(\\d|,)*\\.?\\d*$
This is the proper regex for grouped decimals:
^-?(?:\\.\\d+|\\d{1,3}(?:,\\d{3})*(\\.\\d*)?)$
The following fix handles ungrouped numbers as well:
^-?(?:\\.\\d+|\\d{1,3}(?:\\d*|(?:,\\d{3})+)(\\.\\d*)?)$
But it does not allow somebody to include more than 3 in a group. Thus after 1-3 digits, there must be another digit or a comma or a period or the end.
\\d* handles the case of an immediate period.