Data-Science-Regular-Bootcamp icon indicating copy to clipboard operation
Data-Science-Regular-Bootcamp copied to clipboard

Checking for valid email addresses

Open imsanjoykb opened this issue 4 years ago • 1 comments

pattern = r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"

str_true = ('[email protected]',)
            
str_false = ('testmail.com', '@testmail.com', 'test@mailcom')

for t in str_true:
    assert(bool(re.match(pattern, t)) == True), '%s is not True' %t
for f in str_false:
    assert(bool(re.match(pattern, f)) == False), '%s is not False' %f

imsanjoykb avatar Oct 06 '20 17:10 imsanjoykb

if you add the library import re then the code will run perfectly fine there is an import statement missing

the import re module provides regular expression matching operations similar to those found in Perl. It supports both 8-bit and Unicode strings; both the pattern and the strings being processed can contain null bytes and characters outside the US ASCII range.

import re pattern = r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$)"

str_true = ('[email protected]',)

str_false = ('testmail.com', '@testmail.com', 'test@mailcom')

for t in str_true: assert(bool(re.match(pattern, t)) == True), '%s is not True' %t for f in str_false: assert(bool(re.match(pattern, f)) == False), '%s is not False' %f

2010030122 avatar Sep 13 '22 13:09 2010030122