programming-examples/python/Regular_Expression/Check a decimal with a precision of 2.py
2019-11-15 12:59:38 +01:00

14 lines
383 B
Python

def is_decimal(num):
import re
dnumre = re.compile(r"""^[0-9]+(\.[0-9]{1,2})?$""")
result = dnumre.search(num)
return bool(result)
print(is_decimal('123.11'))
print(is_decimal('123.1'))
print(is_decimal('123'))
print(is_decimal('0.21'))
print(is_decimal('123.1214'))
print(is_decimal('3.124587'))
print(is_decimal('e666.86'))