Reputation:
How can I check if the input is letters not numbers and only the English language?
f="Hello"
print f.isalpha()
True
f="Hello5"
print f.isalpha()
False
f="اهلا"
print f.isalpha()
True
I want it to be True only when f is letters in English and without numbers, like this:
f="اهلا"
print f.isalpha()
False
f="Hello"
print f.isalpha()
True
Upvotes: 1
Views: 1992
Reputation: 53525
# -*- coding: utf-8 -*-
import re
str_a = "abc"
str_b = "اهل"
print re.match(r'^[a-zA-Z]+\Z', str_a) is not None # True
print re.match(r'^[a-zA-Z]+\Z', str_b) is not None # False
Upvotes: 4