题解 | 电话号码格式校验

电话号码格式校验

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

select id,name,phone_number
from contacts
where (phone_number not like '0%' 
    and LENGTH(phone_number) = 10
    and phone_number not REGEXP '[^0-9]'
    and phone_number not like '%-%'
    )
    or 
    (phone_number like '___-___-____'
    and phone_number not like '0%'
    and LENGTH(REPLACE(phone_number, '-', '')) = 10
    and REPLACE(phone_number, '-', '') not REGEXP '[^0-9]');

要注意MYSQL中不支持[^0-9]需要用正则化regexp

not REGEXP '[^0-9]'

全部评论

相关推荐

Cons_W:我9本的,同样找不到。感觉是岗位太少的问题,可能12月份没多少岗位的。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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