[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


using check constraint on email field in sql to restrict addresses

Posted on 2012-09-20
Medium Priority
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 "gmail.com" 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 70

Accepted Solution

Scott Pletcher earned 668 total points
ID: 38418115
Try this:

CHECK( RSVP1_Email LIKE '%@%.edu' )

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

CHECK( RSVP1_Email LIKE '%@%.edu%' )

Assisted Solution

djon2003 earned 668 total points
ID: 38418133
Try using the LIKE operator instead of equal... So :
RSVP1_Email LIKE '%.edu'
LVL 17

Assisted Solution

by:Barry Cunney
Barry Cunney earned 664 total points
ID: 38418144
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 '%.edu')

******     CONSTRAINT chk_EMail CHECK (RSVP1_Email Like '%.edu')

Author Closing Comment

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
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.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

872 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