Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想用 php preg ( preg_match) 验证一个模式。我的模式如下所示:
preg_match
[ [3 or 4 digits] - ][ 7 digits]{1}
例子:
345-4444444 9800-1120222 1111111 1000000 0233-7777777
我试过这个:
pattern = "/\A[\d{3,4}[-]{0,1}]{0,1}\d{7}\z/";
但这是不正确的。请给出正确的模式。
试试这个:
/^(\d{3,4}-)?\d{7}$/
演示:http ://www.rubular.com/r/aOAyuNsVpH