Skip to content

Instantly share code, notes, and snippets.

@bobbravo2
Forked from mrmason/gist:902746
Created May 29, 2011 11:14
Show Gist options
  • Save bobbravo2/997659 to your computer and use it in GitHub Desktop.
Save bobbravo2/997659 to your computer and use it in GitHub Desktop.
// Stops people putting in Invalid nameservers
var nameserver = /^((([a-z0-9]([a-z0-9\-]{0,61}[a-z0-9])?\.)+[a-z]{2,6})|(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))$/i;
$('#configure_domains_form').submit(function() {
if (validNameserver($('input[name="domainns1"]')) && validNameserver($('input[name="domainns2"]')) && validNameserver($('input[name="domainns3"]')) &&
validNameserver($('input[name="domainns4"]'))){
return true;
}else{
return false;
}
});
function validNameserver(ns) {
if(!nameserver.test(ns.val())){
if (ns.val() == ""){
if(ns.attr("name") == "domainns3" || ns.attr("name") == "domainns4"){
// Do nothing, it's ok for these to be Blank
return true;
}
else{
ns.addClass("errorbox");
alert(ns.attr("name") + ": Cannot be blank - you need 2 Nameservers. If in doubt, please use ns1.krystal.co.uk and ns2.krystal.co.uk");
return false;
}
}else{
ns.addClass("errorbox");
alert(ns.val() + " is not a valid nameserver : " + ns.attr("name"));
return false;
}
}
ns.removeClass("errorbox");
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment