Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Aug 2005
    Posts
    252
    Thanks
    23
    Thanked 0 Times in 0 Posts

    Disallowing certain domains in a form

    <input name="EmailOne" type="text" size="32" maxlength="150">

    How can I disallow two domains (ie. @domain1.com and @domain2.com) in the above?

  • #2
    Senior Coder
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    2,636
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You'd need to use a server side language. What processes it at the moment? A PHP script or?

  • #3
    Regular Coder
    Join Date
    Aug 2005
    Posts
    252
    Thanks
    23
    Thanked 0 Times in 0 Posts
    It's currently a perl script but I can use php

  • #4
    Senior Coder
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    2,636
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't know Perl but I found this -

    http://www.tigertom.com/perl-script.shtml

    The 'Fraud Filter' script seems to say it could do what you want. It can currently ban free email addresses so I'm sure you could edit the script to disallow the ones you don't want.

  • #5
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    You could also set up your form so that it would be like this:

    [textbox for address]@[textbox for domain]

    then you could validate the second box:

    PHP Code:
    if($_POST['email_domain'] == [array of bad domains])
      {
      ?>
      <script type="text/javascript">
      alert("This domain is not allowed. Please enter a legal domain.");
      history.go(-1);
      </script>
      <?php
      
    }
    I dont recommend this over a method where you could enter the email all in one box, but it would work

    Sincerely
    Dan

  • #6
    Regular Coder
    Join Date
    Aug 2005
    Posts
    252
    Thanks
    23
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by whizard
    You could also set up your form so that it would be like this:

    [textbox for address]@[textbox for domain]

    then you could validate the second box:

    PHP Code:
    if($_POST['email_domain'] == [array of bad domains])
      {
      ?>
      <script type="text/javascript">
      alert("This domain is not allowed. Please enter a legal domain.");
      history.go(-1);
      </script>
      <?php
      
    }
    I dont recommend this over a method where you could enter the email all in one box, but it would work

    Sincerely
    Dan
    Good idea, I'll try this. I'm having a problem with someone using a form on our site to send spam.

  • #7
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    belts and braces…
    i.e. client-side (js) + server-side (php)…

    e.g.

    test.php
    Code:
    <?php
    
    $badDomains = array('domain1.com','domain2.com');
    
    if (isset($_POST['email'])) {
    
    	$emailArray = explode('@',$_POST['email']);
    	$emailDomain = $emailArray[1];
    
    	if (in_array($emailDomain, $badDomains)) {
    		$msg = 'Blocked domain' ; /* do something bad */
    		} else {
    		/* do something good */
    	}
    
    }
    
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    <head>
    	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
    	<title>test</title>
    	<script type="text/javascript">
    
    	var badDomains = new Array('domain1.com','domain2.com');
    
    	function in_array() {
    
    		var userEmailDomain = document.getElementById('email').value.split('@')[1];
    		var badDomainsStr = badDomains.toString();
    
    		if (badDomainsStr.indexOf(userEmailDomain) != -1) {
    			alert('Blocked domain'); return false;
    		}
    
    	}
    
    /*	OR	*/
    
    	function in_array() {
    
    		var userEmailDomain = document.getElementById('email').value.split('@')[1];
    
    		var n = badDomains.length;
    		for (var i=0; i<n; i++) {
    			if (badDomains[i] == userEmailDomain) {
    				alert('Blocked domain'); return false;
    			}
    		}
    
    	}
    
    	</script>
    </head>
    <body>
    
    <form action="<?php echo $_SERVER['PHP_SELF'] ; ?>" method="post" onsubmit="return in_array();">
    <fieldset>
    
    	<input type="text" id="email" name="email" /><br />
    	<input type="submit" value="submit" />
    
    </fieldset>
    </form>
    
    <p><?php if (isset($msg)) echo $emailDomain." = ".$msg ; ?></p>
    
    </body>
    </html>
    There are two js options in there for checking for the presence of the email domain in the array of blocked domains.

    You may wish to additionally perform some regEx on the input value to check that it's a valid email syntax before accepting it, mainly for the sake of non-blocked email domains.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •