Читая между строк, я расширил определение допустимого ввода и не стал и предположил, что вы хотите захватить только число в описанном формате.
Например, эти числа будут записываться как число справа и являются допустимыми для ввода:
"0.952321 " 0.952321 (trailing spaces stripped)
" 1.20394 " 1.20394 (leading and trailing spaces stripped)
"12.12" 12.12 (no leading or trailing spaces)
"12.123 " 12.123
" .1234 " .1234 (no leading digit -- start with decimal)
"25" 25 (no decimal)
" " " " ? (space. space captured or not)
"12." 12. (1 or 2 digits, decimal, no numbers after decimal)
Не в порядке:
"." just a decimal
"123456789" more than 2 digits lefthand
123 "" ""
123.45678
1.1234567 more than 6 digits right hand
[a-zA_Z] not a digit...
Итак, учитывая, что это регулярное выражение сделает это:
/^\s*( # beginning of string and strip leading space
| \d{1,2}\.? # 1 or 2 digits with optional decimal
| \d{0,2}\.\d{1,6} # 0,1, 2 digits with a decimal with digits
| \s+ # remove if you do not want to capture space
)\s*$ # trailing blanks to the end
/x