using check constraint on email field in sql to restrict addresses

Posted on 2012-09-20
Last Modified: 2012-09-20
I am using sql server 2008 for a help ticket system and we are, not surprisingly, receiving quite a bit of spam--mostly from "" spoofed addresses.  One of the fields is an email address and I was hoping to use a check constraint to ensure that all emails come from the ".edu" domain.

I have been trying this without success and wonder if I am missing something or using improper syntax.  There are times when I do not receive an error, but then it still does not prevent me from entering a restricted address.

I realize the best option is probably to use a captcha, but I am being asked to come up with another idea if possible.

I have tries each of these for the check constraint (not together).  RSVP1_Email is the name of the email field I am trying to restrict to .edu addresses:


If this isn't possible, I thought about checking the addresses against those in another table, which brings up additional issues.

.Thanks in advance for your help.

Question by:lrdchelp
    LVL 68

    Accepted Solution

    Try this:

    CHECK( RSVP1_Email LIKE '' )

    Or, if that doesn't work, then this:

    CHECK( RSVP1_Email LIKE '' )
    LVL 9

    Assisted Solution

    Try using the LIKE operator instead of equal... So :
    RSVP1_Email LIKE ''
    LVL 17

    Assisted Solution

    by:Barry Cunney
    CREATE TABLE Persons
    P_Id int NOT NULL,
    LastName varchar(255) NOT NULL,
    FirstName varchar(255),
    Address varchar(255),
    City varchar(255),
    RSVP1_Email varchar(100)
    CONSTRAINT chk_EMail CHECK (RSVP1_Email Like '')

    ******     CONSTRAINT chk_EMail CHECK (RSVP1_Email Like '')

    Author Closing Comment

    I split the points as you all provided me with the same general information so quickly.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
    This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
    This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
    Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now