PHP정규식preg_match

preg_match정규식

정규식으로 첫 번째 매칭을 검색합니다.

문법

preg_match(string $pattern, string $subject, array &$matches = null): int|false

예제

아래 값을 입력하면 예제에 즉시 반영됩니다.

email
if
preg_match
echo
$email = "user@example.com";
if (preg_match('/^[a-z0-9.]+@[a-z0-9.]+.[a-z]{2,}$/', $email)) {
    echo "유효한 이메일";
}