1
check (phone like'[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]')

This is to check the phone number whether it has exactly 10 digits. But I have no idea about placing number as '[0-9]'. It seems to be a string. So how can we check numbers inside string? Can some one explain this query?

The type of column phone is char(10).

2

You can check the opposite (does not contain chars not in the 0-9 interval).

CHECK (phone NOT LIKE '%[^0-9]%')

Be warned that telephone numbers typically contain also other characters (+,-,.). In that case, you can add allowed symbols to the list:

CHECK (phone NOT LIKE '%[^0-9+-.]%')

See LIKE (Transact-SQL) in the documentation.

-3

This is a regular expression, it´s saying that every value from 0 to 9 is valid and it repeats 10 times. So you have and expression that validates 10 numbers from 0 to 9. I leave this link if you eant to learn further about this, is the basis for programming languages and compilers. https://www.rexegg.com/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.