2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

javascriptでサブドメインに使える文字列か判定する

Last updated at Posted at 2012-12-05

幾つかの条件をjsで判定

function validSubDomainP(subdomain) {
    if (subdomain.length < 3 || subdomain.length > 63) {
        return false;           // too long or too short
    }
    else if (!subdomain.match(/^[a-zA-Z0-9\-]+$/)) {
        return false;           // container illegal characters
    }
    else if (subdomain.match(/(^-|-$)/)) {
        return false;           // begins with - or ends with -
    }
    else if (subdomain.match(/^[a-zA-Z][a-zA-Z]--/)) {
        return false;           // xx-xxxx is not permitted.
    }
    else {
        return true;
    }
};
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?