How many @ symbol can be in an email address?

前端 未结 6 1313
旧巷少年郎
旧巷少年郎 2020-11-30 11:05

Is there any rule for having a specified amount of @ symbol in any email id. Just come to my mind if we\'re to check if an email id is valid or not using PHP.

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 11:43

    My real question is would it make sense to have two @ symbols in an email?
    How would it work?

    I would use filter_var() with FILTER_VALIDATE_EMAIL. Below is a sample use and outputs,

    function testemail($email) {
        echo "'$email' => ";
        var_dump(filter_var($email, FILTER_VALIDATE_EMAIL));    
        echo "
    "; } testemail(''); testemail('myemailsample.com'); testemail('myemail@sample'); testemail('myemail@sample.com'); testemail('myemail@@sample.com'); testemail('myemail@sa@mple.com');

    Output,

    '' => bool(false)
    'myemailsample.com' => bool(false)
    'myemail@sample' => bool(false)
    'myemail@sample.com' => string(18) "myemail@sample.com"
    'myemail@@sample.com' => bool(false)
    'myemail@sa@mple.com' => bool(false)

提交回复
热议问题