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で関数をコーディングして、許可されたパターンで入力文字列をチェックするにはどうすればよいですか?私のパターンは次のようなものです:
1-1341498217
最初のセクションは0から9までの1桁の整数で、ダッシュの後の2番目のセクションは10桁の正の整数です。
ありがとう。
preg_match("/\d-\d{10}/", $string);
?
preg_match("/^\d-[1-9]{10}$/", $string) //^--------------for positive digits
これを使ってpreg_match("/^\d-[1-9]\d{9}$/", $string)
preg_match("/^\d-[1-9]\d{9}$/", $string)