0

I'm having some problems with this Python code I created in order to validate someone entering their email twice, and them checking to see if they have actually entered something and then to check if they match, and then finally to check if they both contain the "@" symbol. I'm still fairly new to python and I'm confused at the moment.

if len(email1) == 0 or len(email2) == 0:
    if email1 != email2:
        while "@" not in email1 or "@" not in email2:
            print "Your email is not valid!"
            email1 = raw_input("\nPlease enter your email address")
            time.sleep(1)
            email2 = raw_input("\nPlease re-enter your email address")
            delay_print("Validating Email......")
        else:
            print "Email accepted!"
    else:
        pass
else:
    f.write(email1)

Can someone help me with this code?

jwodder
  • 54,758
  • 12
  • 108
  • 124

2 Answers2

0

Maybe you want to try something like

while not email1 or not email1 == email2 or not '@' in email1:
flaschbier
  • 3,910
  • 2
  • 24
  • 36
0

why do you use instead regex

import re
import time
regex=re.compile("[^@]+@[^@]+\.[^@]+")

validMail=False
while not validMail:
    email1 = raw_input("\nPlease enter your email address ")
    email2 = raw_input("\nPlease re-enter your email address ")

    if len(email1)>0 and len(email2) > 0:
        if regex.search(email1) and regex.search(email2):
            if email1 == email2:
                print "Email accepted!"
                validMail=True
            else:
                print "different mail"
        else:
            print "Your email is not valid!"
    else:
        print "empty email"
Kristian Damian
  • 1,360
  • 3
  • 22
  • 43
  • 1
    Regex isn't a good tool for checking emails. See here: http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address – sapi Oct 23 '14 at 00:40
  • Ok, regex and email confirmation – Kristian Damian Oct 23 '14 at 00:52
  • I'm not using this for anything complex it's literally just a little school project to then write the entries into a file if they are true. However still being new I hadn't covered much of nested while loops or anything more complex – user3054652 Oct 23 '14 at 21:15