Python regex for finding dots in email address -


i trying make function this:

  • make sure there isn't . @ beginning or @ end of domain.
  • make sure there aren't 2 . in domain.
  • make sure there @ least 1 . in domain.

like blabla@outlook.com, it's suppose make sure isn't:

.blabla@outlook.com. blabla@outlook..com 

and blabla@outlook.com

here code correcting domain:

import re def correct_domain(domain):      if re.search(r'^\.|.$', domain) , re.search(r'\.\.', domain):         return false     else re.search(r'\.', domain):         return true 

.$ should \.$, , and should or. else should elif, , should add final else clause handle domains no dots @ all.

if re.search(r'^\.|\.$', domain) or re.search(r'\.\.', domain):     return false elif re.search(r'\.', domain):     return true else:     return false 

i suggest reorganizing logic bit. can combine first 2 reges, one. in 1 return statement.

return re.search(r'\.', domain) , not re.search(r'^\.|.$|\.\.', domain): 

you these specific checks without regexes, more readable:

return '.' in domain , not \     (domain.startswith('.') or domain.endswith('.') or '..' in domain) 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -