Validating an e-mail based on a specific domains

This is a registration for for my site.
I want to enable registration only for users with an email from a specific domain (i.e
in theory this code should work but in practice it does not.
what am I doing wrong.

$('button').on('click', function() {
  str = $('#email').val();
  str = str.split('@').slice(1);

  var allowedDomains = ['', '', ''];

  if ($.inArray(str[0], allowedDomains) !== -1) {
    alert(str + ' is allowed');
  } else {

<script type="text/javascript" src="//"></script>
<form id="signup" class="js_ajax-forms" data-url="core/signup.php">
  <input name="first_name" type="text" class="form-control" placeholder='First name' required>
  <input name="last_name" type="text" class="form-control" placeholder='Last name' required>
  <input name="username" type="text" class="form-control" placeholder='Username' required>
  <input name="email" type="email" class="form-control" id="email" placeholder='Email' required>
  <input name="password" type="password" class="form-control" placeholder='Password' required>
  <select name="gender" id="gender" class="form-control" required>
    <option value="none">Select Sex:</option>
    <option value="male">Male</option>
    <option value="female">Female</option>
    <option value="other">Other</option>
  <input type="checkbox" class="custom-control-input" name="newsletter_agree" id="newsletter_agree">
  <label class="custom-control-label" for="newsletter_agree">
                                        I expressly agree to receive the newsletter
  <input type="checkbox" class="custom-control-input" name="privacy_agree" id="privacy_agree">
  <label class="custom-control-label" for="privacy_agree"> By creating your account, you agree to our 
    <a href="" target="_blank">Terms</a> & 
    <a href="" target="_blank">Privacy Policy</a> </label>
  <button type="submit" class="btn btn-block btn-success bg-gradient-green border-0 rounded-pill">Sign Up</button></form>

48 thoughts on “Validating an e-mail based on a specific domains”

Leave a Comment