Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7218967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T21:33:29+00:00 2026-05-28T21:33:29+00:00

I am writing a module, in which the email string is validated before it

  • 0

I am writing a module, in which the email string is validated before it gets inserted into the db. When i try to enter invalid email string it prints else block with wrong email message but when i enter the correct email string it doesnt do anything. Here is the code:

   #!/usr/bin/python

import MySQLdb
import re
# Open database connection
db = MySQLdb.connect("localhost","root","root","acl" )

# prepare a cursor object using cursor() method
cursor = db.cursor()

def addUser(email,password):
    
    try:
        if validateEmail(email):
            sql = "INSERT INTO acl_users(email, password) VALUES ('%s', '%s')" % (email, password)
                # Execute the SQL command
            cursor.execute(sql)
                # Commit your changes in the database
            db.commit()
        else:
            print "wrong email"
    except Exception as inst:
 # Rollback in case there is any error
    db.rollback()
    print inst

def validateEmail(email):

    if len(email) > 7:
        if re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", email) != None:
            return True
        else:
            return False
    else:
        return False

Any suggestions please?

edit-1

got the answer guys! after creating instance of the exception in except block i got to know that import re was missing. that solved the problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T21:33:30+00:00Added an answer on May 28, 2026 at 9:33 pm

    in validateEmail you use the module re, but you did not import it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an iOS module which currently sends an email asynchronously (using delegates). It
I'm writing an Account module which should take care of everything about accounts: registration,
I am writing a add-on module which is integrated with an existing PHP application;
I'm writing an Apache module and want to get a string with the Apache
I am writing module which allows to quick add users only by providing First
I'm writing a Python-module which should provide an easy OOP interface to low-level GUI
I'm writing a test for some existing Ruby code which looks something like module
I'm writing a module which serializes others and I've got everything working only I'm
I am writing a small module which will have several different aspects to it,
In the context of organic groups, I am writing a module which will stop

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.