0

I use Respect/Validation and when I use email()...the problem is:

if I validate a string: validator::email()->validate('hello@helloworld.com'); it work!

if I validate a variable: validator::email()->validate($_POST['email']); it doesn't work!

I try to check the content into $_POST['email'] and it's: hello@helloworld.com

the exact output of var_dump($_POST['email']); is: string(21) " hello@helloworld.com"

Matteo Calò
  • 361
  • 1
  • 2
  • 15

1 Answers1

2

As you can see in the output of var_dump($_POST['email']), there is a whitespace in front of the email address:

string(21) " hello@helloworld.com"

So you have to remove that from your parameter, e.g. with trim():

validator::email()->validate(trim($_POST['email']));
str
  • 42,689
  • 17
  • 109
  • 127
  • I don't think this is correct, and the Respect library is actually correctly returning that it's an invalid email address. It should serve an error and the user fix it themselves. IMO – James Feb 03 '23 at 15:07