In: Computer Science
Write a function called checkFormat that will check the format of a given username to make sure it follows some formatting restrictions. This function should take one input parameter – a string that contains the username to be checked. The username should look like [email protected] where cccc can be any 4 lowercase letters. The following conditions must be satisfied to be a valid username:
The length should be 19 characters
The 5th character should be “@”
The username should end with “abcdefghij.edu”
The username should start with 4 lowercase letters
python, use boolean function
def checkFormat(string):
length=len(string)
if(length!=19):
return False
if(string[4]!='@'):
return False
if(string[0:4].islower()==False):
return False
if(string[5:19]!="abcdefghij.edu"):
return False
return True
print(checkFormat("[email protected]"))
print(checkFormat("[email protected]"))
print(checkFormat("[email protected]"))
print(checkFormat("abcdtabcdefghij.edu"))
print(checkFormat("[email protected]"))
print(checkFormat("[email protected]"))