You are apparently using Django.
You are probably better off just using models.IntegerField()
instead of models.TextField()
. Not only will it do the check for you, but it will give you the error message translated in several langs, and it will cast the value from it's type in the database to the type in your Python code transparently.