Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

EbrahemSamer's avatar

PHP Native: Filter_input vs Validate_Email vs Sanitize Email..

What is the difference between sanitizing email and validating email ?

Which one should I use in login or registration form using php native?

Is filter_input function enough to use while getting variables from post request to validate it right?

Thanks.

0 likes
2 replies
bugsysha's avatar
bugsysha
Best Answer
Level 61

What is the difference between sanitizing email and validating email?

FILTER_SANITIZE_EMAIL remove all characters except letters, digits and !#$%&'*+-=?^_{|}~@.[]`.

FILTER_VALIDATE_EMAIL validates whether the value is a valid e-mail address.

Which one should I use in login or registration form using php native?

You should first sanitize it and then validate it.

Is filter_input function enough to use while getting variables from post request to validate it right?

Should be enough. I usually use filter_var. Same end result.

1 like
EbrahemSamer's avatar

@bugsysha Great so I am gonna use just filter_input to sanitize and validate... thanks for replying.

Please or to participate in this conversation.