简体   繁体   English

SQL电话号码限制

[英]Sql phone number constraint

Constraint for Phone Number. 电话号码的约束。 if it is starting with 03 then it must be 11 digits long, but if the digits are 10 then the second digit must not be 3. my code is not working correctly help please. 如果它以03开头,则它必须是11位数字长,但是如果数字是10,则第二位数字不能是3。我的代码无法正常工作,请提供帮助。

c_Phone varchar(11) unique c_Phone check(c_Phone not like '%[^0-9]%'and 
((c_Phone like '03%' and len(c_Phone)=11) or 
(c_Phone like '0^3%' and len(c_Phone)=10))))
alter table dbo.Test
add constraint UQ_Phone unique (c_Phone)


alter table dbo.Test
add constraint CC_Phone  check
(
    c_Phone not like '%[^0-9]%'and 
    ((c_Phone like '03%' and len(c_Phone) = 11) or 
    (c_Phone not like '_3%' and len(c_Phone) = 10))
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM