user3235151
user3235151

Reputation: 5

Php email validation (nothing happend)

Can someone tell me why this is not working to validate this email.

if (filter_var($_POST['Email'], FILTER_VALIDATE_EMAIL)) {
    echo 'Nope';
}

<div class="join input-group">
    <a class="join_topic">Email *</a>
    <input type="text" name="Email" id="Email"  value="<?php echo escape(Input::get('Email')); ?>" class="form-control">
</div>

When i press register nothing happend when i type "123" as the email..

Upvotes: 0

Views: 46

Answers (2)

halabuda
halabuda

Reputation: 384

"123" is not a valid email address by the specifications of the FILTER_VALIDATE_EMAIL filter which is why you're not seeing a response. Enter "[email protected]" and it should work fine. You might also want to and an else conditional while you're at it.

if (filter_var($_POST['Email'], FILTER_VALIDATE_EMAIL)) {
  echo 'Valid Email';
}else{
  echo 'Not Valid';
}

Upvotes: 0

hek2mgl
hek2mgl

Reputation: 157957

According to it's manual, filter_var will return false if the validation fails or the filtered data on success. You if statement should look like this:

if (filter_var($_POST['Email'], FILTER_VALIDATE_EMAIL) === FALSE) {
    echo 'Nope';
}

Upvotes: 1

Related Questions