/* $Id: is_domain_name.js,v 1.1 2003/06/11 20:09:15 nstephen Exp $
 *
 * is_domain_name(x)
 *
 * returns true if x is a valid domain name (RFC 1035)
 * returns false otherwise
 *
 * Author:  Graham Cebulskie
 */

function is_domain_name(x) {
  
  var a = x.split('.');
  if(a.length == 1) {
    return false;
  }
  re = /^([a-zA-Z0-9][-a-zA-Z0-9]*)(\.)?$/;
  re.compile;

  // strip trailing .
  if(x.charAt(x.length - 1) == ".") {
    x = x.substr(0, x.length - 2);
  }
  a = x.split('.');
  for(var i = 0; i < a.length; i++) {
    if(!re.test(a[i])) return false;
  }
  return true;
}


