Skip to content

FILTER_VALIDATE_EMAIL returns FALSE for long emails #19721

@BOPOH

Description

@BOPOH

Description

The following code:

<?php

$email = '1234567890123456789012345678901234567890123456789012345678901234@aaaaaaaaaaaaaa.bbbbbbbbbbbbbbb.ccccccccccccccc.ddddddddddddddd.eeeeeeeeeeeeeee.fffffffffffffff.ggggggggggggggg.hhhhhhhhhhhhhhh.iiiiiiiiiiiiiii.jjjjjjjjjjjjjjj.kkkkkkkkkkkkkkk.lllllllllll.com';
var_dump(
	filter_var($email, FILTER_VALIDATE_EMAIL),
);

Resulted in this output:

bool(false)

But I expected this output instead:

string(255) "1234567890123456789012345678901234567890123456789012345678901234@aaaaaaaaaaaaaa.bbbbbbbbbbbbbbb.ccccccccccccccc.ddddddddddddddd.eeeeeeeeeeeeeee.fffffffffffffff.ggggggggggggggg.hhhhhhhhhhhhhhh.iiiiiiiiiiiiiii.jjjjjjjjjjjjjjj.kkkkkkkkkkkkkkk.lllllllllll.com"

As far as I understand, reason is here: whole string is covered by pattern (?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){255,}) in a local part, so email is considered without at and domain-part, so it is not valid (that's wrong)
Email without one char in local or domain part is valid because it is not covered by this pattern

PHP Version

PHP 8.3.21 (cli) (built: May  9 2025 06:26:54) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.21, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.21, Copyright (c), by Zend Technologies
    with Xdebug v3.4.2, Copyright (c) 2002-2025, by Derick Rethans

Operating System

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions