all groups > sql server programming > october 2007 >
You're in the

sql server programming

group:

check constraint for phone number and email



check constraint for phone number and email Hassan
10/14/2007 11:23:13 PM
sql server programming: As part of the create table for say customers that include phone number and
email address, how can i add a contraint to ensure that phone numbers have
the following constraint met xxx-xxx-xxxx and emails have a @ and a .(dot)
or whatever ways are out there to ensure it follows a particular type ?

Thanks

Re: check constraint for phone number and email Tom Cooper
10/15/2007 3:00:17 AM
You might want to consider whether or not you really want to enforce that
format for phone numbers. It works for the US and Canada and some other
countries, but most international phone numbers are not in that format. But
you can do it with

Create Table Foo (PhoneNumber char(12), Email varchar(100))
Alter Table Foo Add Constraint FooPhoneNumber
Check (PhoneNumber Like
'[0-9][0-9][0-9]-[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]')
Alter Table Foo Add Constraint FooEmail Check (Email Like '_%@_%._%')

Tom

[quoted text, click to view]

AddThis Social Bookmark Button