Created
October 6, 2016 18:42
-
-
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]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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