题解 | 电话号码格式校验

电话号码格式校验

https://www.nowcoder.com/practice/2c2453e909c04c29a04c11e9d6b2c769

select
    id,
    name,
    phone_number
from
    contacts
where
    phone_number not REGEXP '[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]'
    and substring(phone_number, 1, 1) <> "0"
    and (
        (
            phone_number like "%-%-%"
            and length(substring_index(phone_number, "-", -1)) = 4
            and length(substring_index(phone_number, "-", 1)) = 3 
            and length(replace(phone_number, "-", "")) = 10
        )
        or (
            length(phone_number) = 10
            and phone_number not like "%-%-%"
        )
    )

这是可以的吗

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务