javascript - Email validation for specific domain not working -


i have following form

register.php

<form class="form" action="home.php" method ="post" enctype="application/x-www-form-urlencoded">  <input type="email" name="email" placeholder="email address" id="email"/> 

home.php

    <script = "text.javasccript>  $('button').on('click', function(){     str = $('input').val();     str = str.split('@').slice(1);      var alloweddomains = [ 'correct.com' ];      if ($.inarray(str[0], alloweddomains) !== -1) {         alert(str + ' allowed');     }else{         alert('not allowed');     } });     </script> 

i know question has been asked before there no actual answers it. where integrate following function work registration form

this new, edited code doesnt work can help?

my output message 1 saying domain not allowed when type 'allowed' domain in. here code:

register.php

<fieldset style = "border-radius:30px;">   <legend>your personal details:</legend>     <form class="form" action="staffhome.php" method ="post" enctype="application/x-www-form-urlencoded">     <br> <input type="text" name="forename" placeholder ="forename" id="forename"style = "display:inline; float:left;margin-left:5%;"/>       <input type="text" name="surname" placeholder="surname" id="surname"style = "display:inline; float:left;margin-left:5%;"/>        <input type="email" name="email" placeholder="email address" id="email"style = "display:inline; float:left;margin-left:5%;"/><br /><br><br><br>     <script type = "text/javascript">     $('form').on('submit', function(e){     str = $('input').val();     str = str.split('@').slice(1);      var alloweddomains = [ 'wearecallidus.com' ];      if ($.inarray(str[0], alloweddomains) !== -1) {         alert(str + ' allowed');     }else{         alert('not allowed');         e.preventdefault();     }     });   </script>     <input type="text" name="phone" placeholder="phone number" id="phone"style = "display:inline;margin-right:2.5%"/>     <input type="text" name="ext" placeholder="extension number" id="ext"style = "display:inline;margin-left:2.5%;"/><br>   </br> <hr style="border-top: dotted 1px;" />     <br> <input type="text" name="securityq" placeholder="security question" id="securityq" size ="32" maxlength ="60" style = "display:inline;"/>      <input type="text" name="securitya" placeholder="security answer" id="securitya" size="32"style = "display:inline;"/><br />      <br><input type="password" name="password" id="password" value="" size="32" placeholder="type password" minlength="6"/><br><br>      <input type="password" name="password-check" id="password-check" value="" size="32" placeholder ="re-type password" minlength="6"/><br>     </br>      <input id="button" type="submit" value="register" disabled="disabled" name="submit">      </fieldset> 

i same output message every time no matter input, can tell me why?

i if have js in same page instead of externalising it:

<!doctype html> <html> <head> <title>form example</title> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(function() {   var alloweddomains = [ 'correct.com' ];   $('#myform').on('submit', function(e) { // when form submitted     var str = $('#email').val(),     domain = str.split('@')[1]; // split on @ , take second part      if ($.inarray(domain, alloweddomains) == -1) {       alert(domain+' not allowed');       e.preventdefault(); // stop form submission     }   }); }); </script> </head> <body>   <div id="content">     <form id="myform" class="form" action="home.php" method ="post" enctype="application/x-www-form-urlencoded">       <input type="email" name="email" placeholder="email address" id="email"/>       <input type="submit" />     </form>   </div> </body> </html> 

example

$(function() {    var alloweddomains = ['correct.com'];    $('#myform').on('submit', function(e) {      var str = $('#email').val(),        domain = str.split('@')[1];      if (!domain) domain="an empty domain"      $("#emailmsg").html("").hide()      if ($.inarray(domain, alloweddomains) == -1) {        $("#emailmsg").html(domain + ' not allowed').show();        e.preventdefault(); // stop form submission      }    });  });
#emailmsg { display:none; color:red }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>  <div id="content">    <form id="myform" class="form" action="home.php" method="post" enctype="application/x-www-form-urlencoded">      <input type="email" name="email" placeholder="email address" id="email" /> <span id="emailmsg"></span><br/>      <input type="submit" />    </form>  </div>

using form after removing disabled submit , added id="myform" , span:

var alloweddomains = ['correct.com'];    function checkemail(emailid) {    var $email=$("#"+emailid);    var str = $email.val(),domain = str.split('@')[1];    if (!domain) domain = "empty domain";    if ($.inarray(domain, alloweddomains) == -1) {      $email.attr("placeholder", domain + ' not allowed').addclass("redborder");    }    else {      $email.attr("placeholder", "email address").removeclass("redborder");    }         }  $(function() {    $('#myform').on('submit', function(e) {        if (!checkemail("email")) e.preventdefault(); // stop form submission    });    $("#email").on("keyup, blur",function() { checkemail("email"); } );  });
.redborder {    border: 1px solid red  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>  <fieldset style="border-radius:30px;">        <legend>your personal details:</legend>    <form id="myform" class="form" action="staffhome.php" method="post" enctype="application/x-www-form-urlencoded">      <br>      <input type="text" name="forename" placeholder="forename" id="forename" style="display:inline; float:left;margin-left:5%;" />      <input type="text" name="surname" placeholder="surname" id="surname" style="display:inline; float:left;margin-left:5%;" />            <input type="email" name="email" placeholder="email address" id="email" style="display:inline; float:left;margin-left:5%;" />      <br>      <br>      <br>      <br>      <input type="text" name="phone" placeholder="phone number" id="phone" style="display:inline;margin-right:2.5%" />      <input type="text" name="ext" placeholder="extension number" id="ext" style="display:inline;margin-left:2.5%;" />      <br>        </br>      <hr style="border-top: dotted 1px;" />      <br>      <input type="text" name="securityq" placeholder="security question" id="securityq" size="32" maxlength="60" style="display:inline;" />        <input type="text" name="securitya" placeholder="security answer" id="securitya" size="32" style="display:inline;" />      <br />        <br>      <input type="password" name="password" id="password" value="" size="32" placeholder="type password" minlength="6" />      <br>      <br>        <input type="password" name="password-check" id="password-check" value="" size="32" placeholder="re-type password" minlength="6" />      <br>      </br>        <input id="button" type="submit" value="register" name="mysubmit">    </fieldset>


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -