【发布时间】:2012-01-25 01:26:12
【问题描述】:
我正在学习正则表达式,我想在 Python 中使用正则表达式来仅定义整数 - 整数而不是小数。
我可以使用\d 制作一个只允许数字的数字,但它也允许十进制数字,这是我不想要的:
price = TextField(_('Price'), [
validators.Regexp('\d', message=_('This is not an integer number, please see the example and try again')),
validators.Optional()])
如何将代码更改为仅允许整数?
【问题讨论】:
-
regexlib.com 是解决此类问题的金子
标签: python regex django django-forms