Coder Social home page Coder Social logo

tahul / is-valid-domain Goto Github PK

View Code? Open in Web Editor NEW

This project forked from miguelmota/is-valid-domain

3.0 1.0 0.0 190 KB

Validate domain name in JavaScript

Home Page: https://lab.miguelmota.com/is-valid-domain/

License: MIT License

JavaScript 9.71% HTML 9.48% TypeScript 80.81%

is-valid-domain's Introduction

is-valid-domain

Validate domain name in JavaScript

Demo

https://lab.miguelmota.com/is-valid-domain

Install

npm install is-valid-domain

Usage

const isValidDomain = require('is-valid-domain')

isValidDomain('example.com') // true
isValidDomain('foo.example.com') // true
isValidDomain('bar.foo.example.com') // true
isValidDomain('exa-mple.co.uk') // true
isValidDomain('xn--80ak6aa92e.com') // true
isValidDomain('_dnslink.ipfs.io') // true
isValidDomain('exa_mple.com') // false
isValidDomain('-example.co.uk') // false
isValidDomain('example') // false
isValidDomain('ex*mple.com') // false
isValidDomain('*.example.com') // false
isValidDomain('*.com') // false
isValidDomain(3434) // false

isValidDomain('foo.example.com', {subdomain: true}) // true
isValidDomain('foo.example.com', {subdomain: false}) // false
isValidDomain('*.example.com', {wildcard: false}) // false
isValidDomain('*.example.com', {wildcard: true}) // true
isValidDomain('*.example.com', {subdomain: false, wildcard: true}) // false
isValidDomain('はじめよう.みんな') // false
isValidDomain('はじめよう.みんな', {allowUnicode: true}) // true
isValidDomain('ai.') // false
isValidDomain('ai.', {topLevel: true}) // true

view more examples

Test

npm test

Contributing

Adding new domains:

  • Add second level domain to data/second_level_domains.csv
  • Run npm run generate to generate JSON map file
  • Run npm test

FAQ

  • Q: Why is trailing dot . in domain names verified as true?

    • A: Fully qualified domain names allow the trailing dot which represents the root zone. More info here and here.

License

MIT

is-valid-domain's People

Contributors

miguelmota avatar tahul avatar andrewimeson avatar evgencode avatar claydiffrient avatar nahanil avatar pfrazee avatar timjrobinson avatar bluelovers avatar markporamest avatar unggulzmalqp avatar

Stargazers

Marko avatar Matt.  avatar Glenn Layson avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.