Your regex will work just fine if you just add a ^ in front and $ on the back so that the system knows how your line will begin and end.
try it
^[0-9]*[.,]{0,1}[0-9]*$ import re checklist = ['1', '123', '123.', '123.4', '123.456', '.456', '123,', '123,4', '123,456', ',456', '0.,1', '0a,1', '0..1', '1.1.2', '100,000.99', '100.000,99', '0.1.', '0.abc'] pat = re.compile(r'^[0-9]*[.,]{0,1}[0-9]*$') for c in checklist: if pat.match(c): print '%s : it matches' % (c) else: print '%s : it does not match' % (c) 1 : it matches 123 : it matches 123. : it matches 123.4 : it matches 123.456 : it matches .456 : it matches 123, : it matches 123,4 : it matches 123,456 : it matches ,456 : it matches 0.,1 : it does not match 0a,1 : it does not match 0..1 : it does not match 1.1.2 : it does not match 100,000.99 : it does not match 100.000,99 : it does not match 0.1. : it does not match 0.abc : it does not match
source share