#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Domain extension validation


    Hi i have a form where users can enter a domain name they own, i want to add some javascript validation to check if the domain extension they enter is a valid one.

    This is the current validation i have to make sure the input is not empty
    Code:
    		function validateForm()
     {
     var x=document.forms["RegForm"]["DomainReg"].value;
     if (x==null || x=="")
       {
       alert("Please Enter a domain with relevant extension");
       return false;
       }
    How can i add this validation to my code?

    I only want to allow .com | .net | .org domains without the www or http://

    so if they type www.domainname.com it will show a pop up error

    if they type domainname.de (or any other extension to the ones i want to allow) it will show a pop up error.

    Hyphens and digits should be allowed before the extension.
  2. #2
  3. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,127
    Rep Power
    4304
    Welcome to DevShed Forums, rugmonster.

    Would you mind explaining why you want to restrict them to just those three TLDs (top level domains)?

    Why show an error? Wouldn't it be more user-friendly to just silently remove the "www." when the form is submitted?
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0
    Thank you for the welcome message

    Basically i am trying to create a user admin panel where people can add their domain names to their portfolio however at this moment in time i only want to display these extension domains, and i like the idea about silently removing the www etc. could you please point me in the right direction

IMN logo majestic logo threadwatch logo seochat tools logo