Check the registration field

Asked

Viewed 35 times

-1

Is there any way to force in my registration form only use gmail?

            if(filter_var($post_email, FILTER_VALIDATE_EMAIL)){
            if(strlen($post_password) >= 8){
                if(!preg_match('/[\'^£$%&*()}{ @#~?><>,|=_+¬-]/', $post_login)){
                    if(!player_exist_login($post_login) && !player_exist_email2($post_email)){
                        if(player_create($post_login,$post_email,$post_password,$post_chardeletecode)){
                            if(player_send_email_register($post_login,$post_email,$post_password,$post_chardeletecode)){
                                promo_code($promocode);
                                r('verify/');
                            }else{
                                $check_msg = l(170);
                            }
                        }else{
                            $check_msg = l(84);
                        }
                    }else{
                        $check_msg = l(83);
                    }
                }else{
                    $check_msg = l(81);
                }
            }else{
                $check_msg = l(80);
            }
        }else{
            $check_msg = l(79);
        }
  • You can use the function includes JS to check if the substring @gmail.com exists inside the string that stores the value of the email...

  • 1

    If it’s just gmail, why let the user fill in? It wouldn’t be simpler to input the domain BEFORE? [campo input]@gmail.com

1 answer

1

Use a regular expression pattern:

"/@gmail.com$/i"

In practice:

<?php
if (!preg_match("/@gmail\.com$/i", $endereco_email))
{
// Nao tem @gmail.com
}
?>

Learn more about regular expressions.

I don’t know where the email is tested, but I inserted it into the sending function, check:

<?php
function player_create($a,$b,$c,$d){
 return true;
}
function player_exist_login($a){
 return true;
}
function l($a){
 return true;
}

if(player_send_email_register("asdasdasdasdasdasdasd","[email protected]","asdasdasdasdasdasdasd","UTF-8")){

  if (!preg_match("/@gmail\.com$/i", "[email protected]"))
  {
    echo "nao tem";
    exit();
  }
    else {
    echo "tem";
  }

}

?>

  • To check END of string: substr($string, -<tamanho da substring>) == <substring>

  • regex only right?

  • That gives true: strpos("[email protected]","@gmail.com")

  • '|^[A-Z0-9. _%+-][email protected]$|i' is what I get, check?

  • 1

    The regex is not the problem, the version with strpos only, I believe.

  • Edit the check as in the reply and see if it looks good for you, the expression you use is dirty with unnecessary rule.

  • Elisei I updated the post with my php code could kindly check.

  • Unfortunately it did not work and not to prolong too much I put in Pastebin for you to understand my mess.. forgive me.. https://pastebin.com/m5cfTGb5 in this bin look for: Register User Thanks for the promptness.

  • Reduce your code, leave only the part where the verification should be done, it will be more practical and easy to finish your post.

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.