Skip to content

Instantly share code, notes, and snippets.

@graham-thomson
Created October 6, 2016 18:42
Show Gist options
  • Save graham-thomson/8e1754dea9cc1e18b98cedfd02975b80 to your computer and use it in GitHub Desktop.
Save graham-thomson/8e1754dea9cc1e18b98cedfd02975b80 to your computer and use it in GitHub Desktop.
two functions to make sure your string only contains digits [0-9]
def make_sure_digits(string):
import re
regex = u"(^\d+$)"
match = re.match(regex, string)
if match:
return match.group()
return ""
def make_sure_int(string):
try:
return int(string)
except ValueError:
return ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment