[英]mySQL regex in the where clause
SELECT telephone_number
FROM table
WHERE telephone_number REGEXP '^1[() -]*999[() -]*999[() -]*9999$';
how do i make so its valid for any number format and any number like 我如何使它对任何数字格式和任何数字有效
407-888-0909
1(408)998-7654
7776654433
876-7788
right now its only valid for 1-999-999-9999 现在它只对1-999-999-9999有效
Use: 采用:
SELECT telephone_number
FROM table
WHERE telephone_number REGEXP '^1[() -]*[[:digit:]]{3}[() -]*[[:digit:]]{3}[() -]*[[:digit:]]{4}$';
Reference: 参考:
It isn't very wise to store phone numbers in a database with spaces, dashes, parentheses, etc. The most efficient way is to truncate all that garbage to a simple 10 digit number. 将电话号码存储在带有空格,短划线,括号等的数据库中是不明智的。最有效的方法是将所有垃圾截断为简单的10位数字。 That way you can actually store the number in an INTEGER based column instead of a VARCHAR. 这样,您实际上可以将数字存储在基于INTEGER的列而不是VARCHAR中。
SELECT telephone_number
FROM table
WHERE telephone_number REGEXP '[1]?[(]?[[:DIGIT:]]{3}[)]?[-]?[[:DIGIT:]]{3}[-]?[[:DIGIT:]]{4}'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.