In python, I wrote a method to repel an invalid email address.
def isValidEmail(email):
if email[0] == '@':
return False
elif ' ' in email:
return False
elif email.count('@') > 1:
return False
elif email['@':].count('.') < 1:
return False
else:
return True
I wanted to add a condition to repel an email address that does not have a "." After the 4th "@" in the condition, but an error occurred.
The error content is "slice indices must be integers or None or have an __ index __ method" It was. Apparently the contents of the slice need to be an integer.
I prepared a variable that cuts out the domain name after @ in advance, and decided to search for "." In it. success!
def isValidEmail(email):
domain = email.find('@')
if email[0] == '@':
return False
elif ' ' in email:
return False
elif email.count('@') > 1:
return False
elif email[domain:].count('.') < 1:
return False
else:
return True
It may not be the ultimate solution, but it's a solution for the time being!
Recommended Posts