-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresponse.py
More file actions
35 lines (28 loc) · 1.3 KB
/
response.py
File metadata and controls
35 lines (28 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
r"""
When creating a Google Form that prompts users for a short answer (or
paragraph), it’s possible to enable response validation and require that the
user’s input match a regular expression. For instance, you could require that a
user input an email address with a regex like this one:
^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$
Or you could more easily use Google’s built-in support for validating an email
address, per the screenshot below, much like you could use a library in your own
code:
In a file called response.py, using either validator-collection or validators
from PyPI, implement a program that prompts the user for an email address via
input and then prints Valid or Invalid, respectively, if the input is a
syntatically valid email address. You may not use re. And do not validate
whether the email address’s domain name actually exists.
"""
from validator_collection import validators, errors
def main():
email = str(input("What's your email address? "))
try:
is_valid = validators.email(email)
if is_valid:
print("Valid")
else:
print("Invalid")
except errors.InvalidEmailError:
print("Invalid")
if __name__ == "__main__":
main()