Created
October 20, 2010 12:07
-
-
Save think49/636292 to your computer and use it in GitHub Desktop.
jp-domain.js : JPドメインをパースする
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jp-domain.js | |
function JPDomain () { | |
var half_string, hyphen, mark, hiragana, katakana, kanji, TLD, SLD, domain_lastString, alphanum_domain, first_char, middle_char, end_char, japanese_domain; | |
if (!(this instanceof JPDomain)) { | |
throw new Error(this + ' is not a object created by constructor'); | |
} | |
// Base Strings | |
half_string = '[\\dA-Za-z]'; | |
hyphen = '-'; | |
mark = '[\u3005\u309D\u309E\u30FB\u30FC\u30FD\u30FE]'; | |
hiragana = '[\u3041-\u3093]'; | |
katakana = '[\u30A1-\u30F3]'; | |
kanji = '[\u4E00-\u9FA5]'; | |
// Domain's Last Strings | |
TLD = '\\.JP'; | |
SLD = '\\.(?:A[CD]|CO|G[OR]|OR|NE|ED|LG)'; | |
domain_lastString = '(?:' + SLD + ')?' + TLD; | |
// Alphabet & Number Domain | |
alphanum_domain = half_string + '(?:' + half_string + '|' + hyphen + '(?!' + hyphen + ')){1,61}' + half_string + domain_lastString; | |
// Japanese Domain | |
first_char = '(?:' + half_string + '|' + mark + '|' + hiragana + '|' + katakana + '|' + kanji + ')'; | |
middle_char = '(?:' + half_string + '|' + hyphen + '(?!' + hyphen + ')|' + mark + '|' + hiragana + '|' + katakana + '|' + kanji + ')'; | |
end_char = '(?:' + half_string + '|' + mark + '|' + hiragana + '|' + katakana + '|' + kanji + ')'; | |
japanese_domain = first_char + '(?:' + middle_char + '{0,13}' + end_char + ')?' + domain_lastString; | |
// Syntax | |
this.syntaxRegExp = { | |
AlphanumDomain: new RegExp('^' + alphanum_domain + '$', 'i'), | |
JapaneseDomain: new RegExp('^' + japanese_domain + '$', 'i'), | |
JPDomain: new RegExp('^(?:' + alphanum_domain + '|' + japanese_domain + ')$', 'i') | |
}; | |
return this; | |
} | |
// JPDomain.prototype | |
(function () { | |
this.isAlphanumDomain = function (domainString) { | |
return this.syntaxRegExp.AlphanumDomain.test(domainString); | |
}; | |
this.isJapaneseDomain = function (domainString) { | |
return this.syntaxRegExp.JapaneseDomain.test(domainString); | |
}; | |
this.isJPDomain = function (domainString) { | |
return this.syntaxRegExp.JPDomain.test(domainString); | |
}; | |
}).call(JPDomain.prototype); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
下記URLに解説があります。
jp-domain.js
http://vird2002.s8.xrea.com/javascript/jp-domain.html
下記URLを参考にしました。
JPドメイン名の種類 - 使用できる文字 - / JPRS
http://jprs.jp/info/jp-dom/character.html
JPドメイン名の種類 - JPドメイン名の形式例 - / JPRS
http://jprs.jp/info/jp-dom/example.html
JP 属性型 (組織種別型) ・地域型JPドメイン名登録等に関する規則
http://jprs.jp/doc/rule/rule.html