1

Hi i was looking for a way to verify the domain with a provided email address The domain names can be http://www.test.free.com http://www.free.com.au http://www.free.com.au.org http://www.free.com.org or there can be a domain name with any number of sub sub domains and any number of verifications.

the verifying email should contain the domain and this is what i wrote so far

if domain_url is not None and verification_email is not None:

    logging.info('==============================')
    logging.info('BOTH WERE NOT NONE')
    logging.info('==============================')

    domain_email = verification_email.split('@')[1].split('.')[0]

    logging.info('==============================')
    logging.info(domain_email)
    logging.info('==============================')

    verify_domain_url_list = domain_url.split('.')

    if len(verify_domain_url_list) == 4:
        verify_domain_url_list.pop()
        verify_domain_url_list.pop()
    if len(verify_domain_url_list) == 3:
        verify_domain_url_list.pop()


    verify_status = domain_email in verify_domain_url_list

    if verify_status:
        return 'yes'
    else:
        pre_domain_address = verify_domain_url_list[0].split('//')[1]
        if pre_domain_address is not None and \
            domain_email in pre_domain_address:
            return 'yes'
        else:
            return 'no'
    return 'no' 

but this not matching for all the possibilities. can any one give a help?

ox12
  • 17,618
  • 20
  • 63
  • 121
  • 3
    Send a test email, and wait for the user to validate. Really. – Todd A. Jacobs Jun 27 '12 at 06:00
  • Um looking for a pattern to implement this. – ox12 Jun 27 '12 at 06:03
  • See http://stackoverflow.com/questions/201323/how-to-use-a-regular-expression-to-validate-an-email-addresses. – Todd A. Jacobs Jun 27 '12 at 06:04
  • he s not asking how to validate an email address @CodeGnome – Evlikosh Dawark Jun 27 '12 at 06:06
  • 1
    He s asking a way to verify a domain by an email address. He s looking for a pattern for it because he has mentioned 4 variations of domains . – Evlikosh Dawark Jun 27 '12 at 06:08
  • 1
    @Kalanamith domains can have unlimited subdomains ie: a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.google.com is possible (not likely but is possible) most people with domain names do not make emails out of their super-subdomains but on occasion they do. – gabeio Jun 28 '12 at 03:48

1 Answers1

1

You can do it like this, just add the new domains inside the parenthesis.

verification_email = 'fed@test.free.com'
pattern = r'.*@(test.free.com|free.com.au|free.com.au.org|free.com.org)$'

import re
if re.search( pattern , verification_email):
    print('yes')
    # or on your case, return 'yes'

https://github.com/fedmich/StackOverflow-answers/blob/master/python-11220230/regex.py

fedmich
  • 5,305
  • 3
  • 36
  • 52
  • I believe he was more looking for some type of for looped check on the domain itself and if it was possible... adding a new domain for every domain out there would be almost impossible as there are hundreds if not thousands of domains made every day. – gabeio Jun 28 '12 at 03:50
  • 1
    Well if that is the case. rather than managing for loop, he could just customize the pattern as he need it to be .*(free|hotmail|blocked).* this would block domains that has free, hotmail, or blocked in the url of the domain. – fedmich Jun 28 '12 at 03:59
  • I actually meant that... I'm just really tired if you could post the pattern for all possible emails and domain names that is probably what he is looking for... – gabeio Jun 28 '12 at 04:02
  • Yeah, I understand its endless possibilities of domain. But as he said, he's looking for a pattern. – fedmich Jun 28 '12 at 04:06