Home > Enterprise >  PHP email validation function cannot echo JS alert?
PHP email validation function cannot echo JS alert?

Time:11-13

if(isset($_POST['check'])){
    $email =  $_POST['email'];
    if (filter_var($email, FILTER_VALIDATE_EMAIL)) { 
       echo '<script language="javascript">'; 
       echo 'alert(Valid email)';   
       echo '</script>';
    } else { 
       echo '<script language="javascript">'; 
       echo 'alert(Not valid email)';   
       echo '</script>';     
    }
}

i'm trying to show an alert with the result but it's not working. however echo a text working but not JS alert.

why is that? is there another way to do that?

CodePudding user response:

put '<script type="application/javascript">' instead of '<script language="javascript">'

yout script tag attribute is wrong and also you use alert function wrong. change alert(Valid email) to alert("Valid email") and change alert(Not valid email) to alert("Not valid email").

  •  Tags:  
  • php
  • Related