题解 | 电话号码格式校验
电话号码格式校验
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 "%-%-%"
)
)
这是可以的吗
查看3道真题和解析