PHP和Javascript电子邮件验证'@'符号

时间:2017-09-29 04:32:33

标签: javascript php

尝试获取代码以搜索输入的电子邮件地址中是否存在“@”符号,如果符号不存在则回显。没有搜索@ code,一切正常。

check.php

Client application -> authorization endpoint -> login page -> Facebook -> external login callback -> authorization endpoint -> client application.

register.php

CATransition *transition = [[CATransition alloc] init];
        transition.duration = 0.1;
        transition.type = kCATransitionPush;
        transition.subtype = kCATransitionFromLeft;
        [viewToAnimate.layer addAnimation:transition forKey:kCATransition];

编辑:我有一个用于php后端验证的内置过滤器。但是,我正在尝试通过这些代码进行前端验证。如果有人知道如何修复我的脚本请发布。我收到错误

  

在第13行的/check.php中调用未定义的函数str()

第13行

<?php
include '/connect.php'; //connects to mysql

$email = mysqli_real_escape_string($connect, $_POST['email']);

$check = mysqli_query($connect, "SELECT email FROM users WHERE email='$email'");
$check_num_rows = mysqli_num_rows($check);

if ($email==NULL) {
    echo 'Enter an email';
} elseif (strlen($email)<6) {
    echo 'Please enter a valid email';
} elseif (str($email).indexOf('@') == -1) {
    echo 'Please enter a valid email';
} else {
    if ($check_num_rows==0) {
        echo 'Email valid';
    } elseif ($check_num_rows==1) {
        echo 'Email already registered';
    }
}

4 个答案:

答案 0 :(得分:2)

验证电子邮件的更好方法是使用针对此类事情的内置过滤器

<?php

    include '/connect.php'; //connects to mysql

    $email = mysqli_real_escape_string($connect, $_POST['email']);

    $check = mysqli_query($connect, "SELECT email FROM users WHERE email='$email'");
    $check_num_rows = mysqli_num_rows($check);

    if ( filter_var($email, FILTER_VALIDATE_EMAIL) ) {
        if ($check_num_rows==0) {
            echo 'Email valid';
        } elseif ($check_num_rows==1) {
            echo 'Email already registered';
        }
    } else {
        echo 'Please enter a valid email';
    }
?>

您的代码无法正常工作的原因是因为PHP没有strindexOf方法,您应该使用strpos之类的代码< / p>

if (strpos($email, '@') === false) { ...

答案 1 :(得分:1)

它不仅会验证电子邮件地址,还会对意外字符进行清理:

{{1}}

答案 2 :(得分:0)

您可以使用默认的php电子邮件验证     

if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
  echo("$email is a valid email address");
} else {
  echo("$email is not a valid email address");
}
?>

您也可以在https://eval.in/870776

查看此信息

答案 3 :(得分:0)

试试这个: -

function isValidEmailAddr ($email) {
    if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
      return true;
    } else {
      return false;
    }
}

用法: -

include('path/to/lib.php');
$test = 'email@foo.bar';
if(isValidEmailAddr($test) == true){
 echo "good to go";
} else { echo "try again babe!" }