0
Is it possible to write a program in python that checks the validity of an email address without using regular expressions?
This semester at school we've been learning OOP using Python, but we haven't tackled anything concerning regular expressions, yet on the midsemester exams we were asked to write a program that checks validity of an email. Here on Soulo Learn I have learnt how to do it using RE. but is there any other way of doing it? How? Below is the code I made: https://code.sololearn.com/cKGPv447QQd8/?ref=app
6 Réponses
+ 1
# if it's just a search for a specific extention on the end of the string
# use endswith()
test = ['sds@must.ac.mw',
'qwqw@must.ac.mwx',
'fdfd@must.ac.mw',]
the_suffix = '@must.ac.mw'
for item in test:
print(item.endswith(the_suffix))
+ 1
@spcan Do you mind explaining your code? I don't really follow what's happening. Also, I was looking for one verifying a specific email extension. i.e. in this case "@must.ac.mw"
+ 1
It loops over the string you give the function and keeps track of all checkpoints you give it. In my code it checks wether or not it has looped over the @ symbol (arroba in my language) and how many dots it has after the @
A way to do that would be to loop over the string until you find the @ symbol and then cut the substring after the @ and compare it to the extension you want
+ 1
Thanks a lot. That makes a lot of sense. will give your code an upvote now that I understand.
+ 1
wow, @richard that is actually easy and simple, kind of self-explanatory too... thanks for the insight, you guys have shown me to think outside the box
0
Just manually check
This code checks for an email with this structure:
name (.optional)@name (.optional).com
https://code.sololearn.com/c4NwYRpqMNzQ/?ref=app