>perl -wMstrict -le "use Regexp::Common; ;; for my $t (qw( 12.12 123.123 1 12 123 1. 12. 123. .1 .12 .123 0.1 1.0 0.0 1234.0 1234 0.1234 .1234 -123 -.12 -0.1 )) { my $ok = $t =~ m{ \A (?! .* \d{4}) $RE{num}{real} \z }xms; printf qq{%s '$t' \n}, $ok ? 'accept' : 'REJECT'; } " accept '12.12' accept '123.123' accept '1' accept '12' accept '123' accept '1.' accept '12.' accept '123.' accept '.1' accept '.12' accept '.123' accept '0.1' accept '1.0' accept '0.0' REJECT '1234.0' REJECT '1234' REJECT '0.1234' REJECT '.1234' accept '-123' accept '-.12' accept '-0.1'