Tim
Tim

Reputation: 8921

In a T-SQL check constraint, how to allow either a specific pattern or the empty string

I have a phone-number pattern in place now. I'd like to allow the empty string temporarily as a valid value. What is the pattern for that? Here's the existing check:

( ([fax] like '[1-9][0-9][0-9].[0-9][0-9][0-9].[0-9][0-9][0-9][0-9]'))

How would that pattern be changed to accept the empty string as well?

Upvotes: 0

Views: 164

Answers (1)

GMB
GMB

Reputation: 222442

How would that pattern be changed to accept the empty string as well?

You could just use or:

(   
    [fax] = ''
    or [fax] like '[1-9][0-9][0-9].[0-9][0-9][0-9].[0-9][0-9][0-9][0-9]'
)

Upvotes: 1

Related Questions