5
I know how the FILTER_SANITIZE_EMAIL
works, but what I can’t understand is why it doesn’t remove the following characters:
! # $% & '* + - =? ^ _ `{|} ~ @. [] .
- I know that in the documentation you are specifying that it does not remove, but what is the reason for this?
- I’ve never seen an email with
Luan{}martins*@hotmail.com
, this behavior is not abnormal? - If he can’t verify the e-mail because I should use it?
Form
<form method="POST">
<input type="text" name="string">
<input type="submit" name="btn" value="btn"></form>
PHP
$string = filter_input(INPUT_POST, 'string' ,FILTER_SANITIZE_EMAIL, FILTER_VALIDATE_EMAIL);
I would like to understand this reason, at the moment I am writing about the types of filter and I really did not find anything that made me understand the reason to accept the characters I spoke, whenever I am developing and I want to ensure that is an email use the HTML5
, but I like to use filters and normally use parern
The documentation does not quote, but probably is because of RFC 5322, that allows these characters in an email (as strange as it may seem).
– hkotsubo
An excellent observation, besides that in the html input element happens the same, if you put type="email" it valid the email and send with these characters.
– user78859
I had not noticed that in html it also accepted the characters, but I always had this doubt that the reason of acceptance of the characters, to validate always withdrew with the parern, now that I read the past document I understood.
– Martins Luan
But it wouldn’t be for a case where the email address was a
IPV6
? Just kicking it. Although these characters there are quite unusual– Wallace Maxters
@Wallacemaxters Actually these characters are allowed in the username (before the
@
). Though unusual and strange, is valid according to the RFC. PHP probably follows the same rule, but I still haven’t found a source to say that for sure (from what I’ve seen, the documentation doesn’t say yes or no)– hkotsubo
You can create your own filter by configuring a filter.default so you can adjust the filter to any way you want, I hope I’ve helped!
– GitSheep