0

I have seen a similar question asked here Jquery how to validate domain name but I cannot seem to get this example to work with my code.

I would basically like to perform a reg ex against an input text box, and validate via jquery to see if it matches my search criteria for a domain name. The format must be

domainname.co.uk or .com/.org/.net (no http:// or https:// and no subdomain)

My code currently :

if(!/([a-z0-9-]+\.(?:com|net|org|co.uk))(?:\/|$)/$("#domain").val()) {
        $('#error').html("Invalid domain name, , please correct before proceeding.");
        return false;   
}
Community
  • 1
  • 1
Graeme Leighfield
  • 2,639
  • 3
  • 20
  • 38

1 Answers1

4
!/([a-z0-9-]+\.(?:com|net|org|co.uk))(?:\/|$)/$("#domain").val())

Should be:

!/([a-z0-9-]+\.(?:com|net|org|co\.uk))(?:\/|$)/.test($("#domain").val()))
//                              ^              ^^^^^
gdoron is supporting Monica
  • 136,782
  • 49
  • 273
  • 342