Python check for numeric value
2 answers
You can use isdigit()
if anytext
always has a type string
.
For example:
'Hello World'.isdigit() # returns False
'1234243'.isdigit() # returns True
So with your code:
anytext = request.POST.get("my_text", "")
if anytext.isdigit():
# perform action on numeric string
else:
# perform action on alphanumeric string
+2
source to share