Guest User

Only one dot in a row (Email Address Validation Check)

a guest
Jun 9th, 2017
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.40 KB | None | 0 0
  1. def ismorethan6(emailaddress): #defining name of function and parameter
  2.     emailaddress1 = emailaddress.split("@")[0].replace(".","") #store email name (without dots) part in variable
  3.  
  4.     if len(emailaddress1) < 6: #if lenght of email name part is lesser than 6 characters
  5.         return (False,len(emailaddress1)) # return tuple False and lenght of email name part
  6.     return (True,len(emailaddress1)) # if first if condition failed return tuple with True and lenght of email name part from this function
  7.  
  8.    
  9. def nomdot(emailaddress): # Function name nomdot "NO Multi DOTs" and parameter emailaddress Pac Man eats dots nom nom
  10.     flag=False # flag variable initiated with False
  11.     for char in emailaddress: # for every character stored in variable named emailaddress
  12.         if char.isalnum(): # check if character is alpha numeric
  13.             flag=True # if yes flag equals to 1
  14.         elif char == "@" or char == ".": #else if character is @ or .
  15.             if flag == True: # and flag equals to 1
  16.                 flag = False # set flag to 0 (store in variable called flag number 0)
  17.             elif flag == False: #else if flag equals to 0
  18.                 return False # outcome of function is negative
  19.     if flag == True: # if flag equals to number 1
  20.         return True # outcome of function is positiv
  21.  
  22. # function named "only one @"
  23. # checks there's only one "at" sign
  24. # in whole email address string"
  25. def onlyoneat(emailaddress):
  26.     if emailaddress.count("@") == 1:
  27.         return True
  28.     return False
  29.    
  30. emailaddress = "[email protected]" #unused test email address
  31. while(1): # this is while loop. while 1 run code inside while loop
  32.     emailaddress = input("Enter email address for validation check: ") #get input from keyboard and store it in emailaddress string variable
  33.     if not emailaddress: # if emailaddress variable is None or empty
  34.         break; #break while loop. goes out of loop. in this case means it will stop running our code
  35.     if ismorethan6(emailaddress)[0] and nomdot(emailaddress) and onlyoneat(emailaddress): # if email address has at least 6 characters and has no at sign and/or dot more than two times in a row (e.g. it won't accept @@ .@ .. @.) and has only one at sign in whole email address
  36.         print("Valid",ismorethan6(emailaddress)) # then email address is valid
  37.     else:
  38.         print("Invalid :(",ismorethan6(emailaddress)) # else it's not
Advertisement
Add Comment
Please, Sign In to add comment