0

Ok so i need to make a program that you put in an email address and it checks for the @ symbol and then makes sure its not the first digit or the last digit. Now i know that there is " like s.islower( for lowercase) and s.isupper but i dont know if theres a s.is "@"

can someone help me?

def main():

    print "This program validates a email address"
    email = raw_input("Enter Your email: ")
    
   if isValid(email):
        print ("That is a valid email")
       
    else:
        print ("That email is not valid.")
       
    raw_input("\nPress <enter> to close window.")


def isValid(s):
    
    
    if s.is"@"() == 0:
        print "There is no @ symbol"
        return False
    if s.isfirst(@) == 0:
        print "the @ cannot be first"
        return False
    if s.islast(@) == 0:
        print "the @ cannot be last"
        return False
    
    return True

main()
4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by vegaseat
0

Ok i got the endswith and the startswith. but im not sure how to check for the @ symbol. so what method checks for a symbol?

1

To check for a valid email adress regular expression is a god tool.

import re

mail_input = raw_input("Enter your email: ")

if re.match(r"\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b\Z", mail_input, re.IGNORECASE):
    print ("That is a valid email")
else:
    print ("That email is not valid")

Edited by snippsat: n/a

1

Or keep it simple:

if "@" not in mail_input:
    print "There is no '@' symbol!"

Edited by txwooley: typo

0

Ok i got the endswith and the startswith. but im not sure how to check for the @ symbol. so what method checks for a symbol?

You are on the right track ...

def isValid(s):
    if "@" not in s:
        print "There is no @ symbol"
        return False
    if s.startswith("@"):
        print "the @ cannot be first"
        return False
    if s.endswith("@"):
        print "the @ cannot be last"
        return False
    return True

# testing ...
isValid("Cyproz@hotshot.com")
isValid("Cyprozathotshot.com")
isValid("@Cyprozathotshot.com")
isValid("Cyprozathotshot.com@")
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.