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.
Twitter の名前は最小 1 文字、最大 20 文字にすることができるため、Twitter ユーザー名を検証するための次の正規表現関数は機能しません。ただし、これをテストしたところ、20 文字を超えるユーザー名を使用できます。どこで私は間違えましたか?
public function val_username($subject) { return (bool)preg_match('/[a-zA-Z0-9_]{1,20}/', $subject); }
$とを忘れた^
$
^
/^[a-zA-Z0-9_]{1,20}$/動作するはずです
/^[a-zA-Z0-9_]{1,20}$/
public function val_username($subject) { return (bool)preg_match('/^[a-zA-Z0-9_]{1,20}$/', $subject); }