Hostname Schema

The value has to a valid domain name.

This is a specialization of the StringSchema the methods used there are used in the same way as in Any Schema:

  • title()
  • detail()
  • required()
  • forbidden()
  • default()
  • allow()
  • deny()
  • valid()
  • invalid()
  • raw()

And the methods from String Schema:

  • makeString()
  • trim
  • replace()
  • lowerCase()
  • upperCase()
  • alphaNum
  • hex
  • allowControls
  • noHTML
  • stripDisallowed
  • min()
  • max()
  • length()
  • match()
  • notMatch()

1. Checking

1.1. allow(list) / deny(list)

In principal this is identical to the any type and also valid(item) and invalid(item) may be used but the matching is a way complexer.

You can give the full domain name, sub domains, domains or TLD in the list. The more precise element has precedence over the more general ones.

const schema = new DomainSchema()
  .allow('de')
  .deny('spam.de')

1.2. min(limit) / max(limit) / length(limit)

The length here works on the number of labels within the domain name. Thats the structural depth of it.

1.3. checkDNS(type)

You can check that the server name is registered in the DNS. It is also possible to allow only names with specific entries if type is given. The type may be a list of, default is 'ANY':

  • 'A' IPv4 addresses
  • 'AAAA' IPv6 addresses
  • 'CNAME' canonical name records
  • 'MX' mail exchange records
  • 'NAPTR' name authority pointer records
  • 'NS' name server records
  • 'PTR' pointer records
  • 'SOA' start of authority records
  • 'SRV' service records
  • 'TXT' text records
  • 'ANY' any records
const schema = new DomainSchema().checkDNS() // check for any record
const schema = new DomainSchema().checkDNS('MX') // check for mx record
schema.checkDNS(false) // to remove settings

2. Formatting

2.1. punycode

The punycode is an ASCII presentation of international domain names. This is the form which is used internally in the DNS while the browser accepts and displays the unicode representation of it.

const schema = new DomainSchema().punycode() // lügen.de -> xn--lgen-0ra.de
schema.punycode(false) // to remove settings

2.2. resolve

If this flag is set the domain will be resolved to its IP which is given back.

const schema = new DomainSchema().resolve() // alinex.de -> 95.173.102.23
schema.resolve(false) // to remove settings

results matching ""

    No results matching ""