An HTML form returns me a string of a number entered by a user. How do I use regular expressions to see if it is capable of being a number or not. I do not simply want to strip away commas and see if it can be cast to int, nor do I like the locale.atoi method as the strings will evalaute to numbers even if they are nonsense (e.g. locale.atoi('01,0,0') evaluates to 100).
NB this validation only occurs if the string contains commas
The re pattern should be:
1st character is 1-9 (not zero) 2nd and 3rd characters are 0-9 Then 3 digits 1-9 and a comma repeated between 0 and 2 times (999,999,999,999 is largest number possible in the program) Then finally 3 digits 1-9
compiled = re.compile("[1-9][0-9]{0,2},(\d\d\d,){0,2}[0-9]{3}")
which is not matching the end of the string correctly, for example:
re.match(compiled, '123,456,78')
is matching. What have I done wrong?
([1-9][0-9]{0,2},(\d\d\d,){0,2}[0-9]{3})Could you post matching examples?