I have a textarea that can accept only whole and decimal numbers on each new line. I need a JQuery regex that will validate the input on Focus Out. So basically the value on each line should be either an integer or a decimal.
Ex:
Valid Scenarios:
1
51425.125
2552
600000
1.51425
3.65
Invalid Scenarios:
.123
123.
123. 56
1213.56.25
234. (spaces after the decimal point)
I have tried various regex combinations but none seemed to work perfectly:
\b\s([-+]?(\d+|\.\d+|\d+\.\d*))($|[^+-.])
This regex fails when there are 2 decimal values.
\b[0-9\s]*(\.*[0-9\s]*)*
This regex allows space in between and after values.
\b(?:^|\s)(?=.)((?:0|(?:[1-9](?:\d*|\d{0,2}(?:,\d{3})*)))?(?:\.\d*[1-9])?)(?!\S)
This regex doesn't allow the user to enter multi-line values.
Went through several links but none seems to work for me:
Regular Expression for Decimal or Blank
Regular expression - number with spaces and decimal comma
Decimal number regular expression, where digit after decimal is optional
http://regexone.com/problem/matching_decimal_numbers