When you receive the string, write a Python program to check if the string is a valid email address or not.
Email — it is a string (a subset of ASCII characters), separated into two parts by the @ symbol, "personal_info" and the domain, that is, personal_info @ domain.
Examples :
Input: [email protected] Output: Valid Email Input: [email protected] Output: Valid Email Input: ankitrai326.com Output: Invalid Email
In this program we use the search ()
method of the re module ... so let’s see a description about that.
re.search (): this method either returns None (if the pattern doesn’t match) or re.MatchObject
which contains information about the corresponding part of the string. This method stops after the first match, so it is better suited for validating regular expressions than extracting data.
Let’s take a look at a Python email validation program:
< code class = "keyword"> else
|
Exit:
Valid Email Valid Email Invalid Email