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