Products
GG网络技术分享 2025-03-18 16:15 0
How to write regular expression for following conditions:
So for I can do only for first two conditions. I am not sure how to do the third conditions
My code is if (!preg_match(\'/^[0-9]{8}$/\', $number))
You\'re almost there. Simply remove the first number from the character class and validate it at the start of your pattern...
/^(8|9|6)\\d{7}$/
FYI - \\d
is the escape sequence for digits. I suppose you could also use this
/^[896]\\d{7}$/
as it means about the same thing when you\'re only watching for a single character at the start.
除非您以前使用过正则表达式,否则您可能不熟悉一些术语。但是,毫无疑问,您已经使用过不涉及脚本的某些正则表达式概念。
例如,您很可能使用 ? 和 * 通配符来查找硬盘上的文件。? 通配符匹配文件名中的 0 个或 1 个字符,而 * 通配符匹配零个或多个字符。像 data(\\w)?\\.dat 这样的模式将查找下列文件:
Demand feedback