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

15th Jan 2018, 5:45 PM
Audrey Mwale
Audrey Mwale - avatar
6 odpowiedzi
+ 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))
15th Jan 2018, 9:01 PM
richard
+ 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"
15th Jan 2018, 6:12 PM
Audrey Mwale
Audrey Mwale - avatar
+ 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
15th Jan 2018, 6:19 PM
spcan
spcan - avatar
+ 1
Thanks a lot. That makes a lot of sense. will give your code an upvote now that I understand.
15th Jan 2018, 6:25 PM
Audrey Mwale
Audrey Mwale - avatar
+ 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
15th Jan 2018, 9:18 PM
Audrey Mwale
Audrey Mwale - avatar
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
15th Jan 2018, 6:04 PM
spcan
spcan - avatar