Hi I have problem with correct url validation with query string containing email address like:
https://example.com/[email protected]
this email is ofc correct one [email protected]
is an alias of [email protected]
I have regex like this:
$page = trim(preg_replace('/[\\0\\s+]/', '', $page));
but it don't work as I expected because it replaces +
to empty string what is wrong. It should keep this +
as alias of email address and should cut out special characters while maintaining the correctness of the address.
Example of wrong url with +
:
https://examp+le.com/?email=example@exam+ple.com
Other urls without email in query string should be validating correctly using this regex
Any idea how to solve it?
I think this is what you looking for:
Gives the following output:
At first, I replaced the valid
+
sign on email addresses with a#
, then removing all the remainings+
, after that, I replaced the#
with+
.This solution won't work if there's a
#
s on the URL if so you will need to use another character instead of#
for the temporary replacement.