/********************************************* desc: Form Checker library , and use FormCheck CLASS *********************************************/ function trim(value) { return value.replace(/^\s+|\s+$/g,""); } /********************************************* FORM CHECKER *********************************************/ function FormChecker() {} FormChecker.prototype.echoAlert = fc_echoAlert; FormChecker.prototype.isEmpty = fc_isEmpty; FormChecker.prototype.isValidIP = fc_isValidIP; FormChecker.prototype.isValidIPorSubnetwork = fc_isValidIPorSubnetwork; FormChecker.prototype.isPrivateIP = fc_isPrivateIP; FormChecker.prototype.isValidIPv6 = fc_isValidIPv6; FormChecker.prototype.isZone = fc_isZone; FormChecker.prototype.isDomain = fc_isDomain; FormChecker.prototype.isSrvDomain = fc_isSrvDomain; FormChecker.prototype.isTxtDomain = fc_isTxtDomain; FormChecker.prototype.isValidSubDomain = fc_isValidSubDomain; FormChecker.prototype.isURL = fc_isURL; FormChecker.prototype.isNumber = fc_isNumber; FormChecker.prototype.isNaturalNumber = fc_isNaturalNumber; FormChecker.prototype.isValidID = fc_isValidID; FormChecker.prototype.isValidName = fc_isValidName; FormChecker.prototype.isValidSpaceName = fc_isValidSpaceName; FormChecker.prototype.isValidPassword = fc_isValidPassword; FormChecker.prototype.isValidAuthcode = fc_isValidAuthcode; FormChecker.prototype.isValidEmail = fc_isValidEmail; FormChecker.prototype.isValidEmailLength = fc_isValidEmailLength; FormChecker.prototype.isValidMXRank = fc_isValidMXRank; FormChecker.prototype.isValidMailForward = fc_isValidMailForward; FormChecker.prototype.isValidOfflineMsg = fc_isValidOfflineMsg; FormChecker.prototype.isValidSubnet = fc_isValidSubnet; FormChecker.prototype.isPTRZone = fc_isPTRZone; FormChecker.prototype.isWithinRange = fc_isWithinRange; FormChecker.prototype.proofreadCase = fc_proofreadCase; FormChecker.prototype.htmlspecialchecker = fc_htmlspecialchecker; /*** fc_echoAlert() {{{ ***/ function fc_echoAlert() { alert('hi'); } /*** }}} ***/ /*** fc_isWithinRange() {{{ ***/ function fc_isWithinRange(value, min, max) { if(isNaN(value) || value < min || value > max) { return false; } else { return true; } } /*** }}} ***/ /*** fc_isEmpty(value) {{{ ***/ function fc_isEmpty(value) { if (value == null) return true; var trimedValue = trim(value); if (trimedValue == '') return true; return false; } /*** }}} ***/ /*** fc_isValidIP(ip) {{{ ***/ function fc_isValidIP(ip) { /* ip = trim(ip); if (ip == '') return false; ip_items = ip.split('.'); field_number = ip_items.length; // IP has 4 fields if (field_number != 4) return false; // 255.255.255.255 is not valid if (ip == '255.255.255.255') return false; // 0 <= IP item area <= 255 for (i = 0; i < field_number; i++) { var item = ip_items[i]; item = new Number(item); alert(ip + '_-_' + item.toString()); if (isNaN(item)) return false; // not numbert string if (item < 0 || item > 255) return false; // 0 ~ 255 } return true; */ ip = trim(ip); if (ip == '255.255.255.255') return false; var pattern = /^((((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5]))))$/; return pattern.test(ip); } /*** }}} ***/ /*** fc_isValidIPorSubnetwork(ip) {{{ ***/ function fc_isValidIPorSubnetwork(ip) { ip = trim(ip); var re = /^([\w\.]+)($|\/\d{1,2})/; var m = re.exec(ip); if (m == null) return false; else { var isValidIP = fc_isValidIP(m[1]); var isValidSubnetMask = false; if (m[2] == "" || (m[2].substr(1) >= 0 && m[2].substr(1) <= 32)) isValidSubnetMask = true; return isValidIP && isValidSubnetMask; } } /*** }}} ***/ /*** fc_isValidIPv6(ip) {{{ ***/ function fc_isValidIPv6(ip) { ip = trim(ip); var pattern = /^(^(([0-9A-Fa-f]{1,4}(((:[0-9A-Fa-f]{1,4}){5}::[0-9A-Fa-f]{1,4})|((:[0-9A-Fa-f]{1,4}){4}::[0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4}){0,1})|((:[0-9A-Fa-f]{1,4}){3}::[0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4}){0,2})|((:[0-9A-Fa-f]{1,4}){2}::[0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4}){0,3})|(:[0-9A-Fa-f]{1,4}::[0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4}){0,4})|(::[0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4}){0,5})|(:[0-9A-Fa-f]{1,4}){7}))$|^(::[0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4}){0,6})$)|^::$)|^((([0-9A-Fa-f]{1,4}(((:[0-9A-Fa-f]{1,4}){3}::([0-9A-Fa-f]{1,4}){1})|((:[0-9A-Fa-f]{1,4}){2}::[0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4}){0,1})|((:[0-9A-Fa-f]{1,4}){1}::[0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4}){0,2})|(::[0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4}){0,3})|((:[0-9A-Fa-f]{1,4}){0,5})))|([:]{2}[0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4}){0,4})):|::)((25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{0,2})\.){3}(25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{0,2})$$/; return pattern.test(ip); } /*** }}} ***/ /*** fc_isZone() {{{ ***/ function fc_isZone(domain) { domain = trim(domain); var length = domain.length; if (length > 70) return false; var domainPattern = /^(([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])))$/ return domainPattern.test(domain); } /*** }}} ***/ /*** fc_isDomain() {{{ ***/ function fc_isDomain(domain) { domain = trim(domain); var length = domain.length; //alert(length); if (length > 200) return false; var domainPattern = /^((\*\.)?([a-zA-Z0-9\_]([a-zA-Z0-9\-\_]{0,61}[a-zA-Z0-9])?\.)+([a-zA-Z0-9\_]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])))$/ return domainPattern.test(domain); } /*** }}} ***/ /*** fc_isSrvDomain() {{{ ***/ function fc_isSrvDomain(domain) { domain = trim(domain); var length = domain.length; //alert(length); if (length > 200) return false; var domainPattern = /^((\*\.)?([a-zA-Z0-9\_]([a-zA-Z0-9\-\_]{0,61}[a-zA-Z0-9])?\.)+([a-zA-Z0-9\_]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])))$/ return domainPattern.test(domain); } /*** }}} ***/ /*** fc_isTxtDomain() {{{ ***/ function fc_isTxtDomain(domain) { domain = trim(domain); var length = domain.length; //alert(length); if (length > 200) return false; var domainPattern = /^((\*\.)?([a-zA-Z0-9\_]([a-zA-Z0-9\-\_]{0,61}[a-zA-Z0-9])?\.)+([a-zA-Z0-9\_]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])))$/ return domainPattern.test(domain); } /*** }}} ***/ /*** fc_isValidSubDomain() {{{ ***/ /*** 새로운 도메인규약에는 서브도메인명에 언더스코어가 들어갈 수 있다. */ function fc_isValidSubDomain(subDomain) { subDomain = trim(subDomain); var length = subDomain.length; if (length > 61) return false; var subDomainPattern = /^((\*.+)|(([A-Za-z0-9\-\_])+\.+([A-Za-z0-9\-\_])+))$/ return subDomainPattern.test(subDomain); } /*** }}} ***/ /*** fc_isSrvSubDomain() {{{ ***/ function fc_isSrvSubDomain(subDomain) { subDomain = trim(subDomain); var length = subDomain.length; //alert(length); if (length > 61) return false; var subDomainPattern = /^((\*.+)|(([A-Za-z0-9\-\_])+\.+([A-Za-z0-9\-])+))$/ return subDomainPattern.test(subDomain); } /*** }}} ***/ /*** fc_isURL() {{{ ***/ function fc_isURL(url) { var pattern = /^([A-Za-z]{3,9})\:\/\/(((([a-z0-9\-])+\.)+([a-z]{2}\.[a-z]{2}|[a-z]{2,4}))|((((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))))/ return pattern.test(url); } /*** }}} ***/ /*** fc_isNumber() {{{ ***/ function fc_isNumber(value) { if (isNaN(value) == true) { return false; } else return true; } /*** }}} ***/ /*** fc_isNaturalNumber() {{{ ***/ function fc_isNaturalNumber(value) { var length = value.length; var x = parseFloat(value); if (!isNaN(value) && (x | 0) === x) { return length == x.toString().length; } else { return false; } } /*** }}} ***/ /*** fc_isValidID(id) {{{ ***/ function fc_isValidID(id) { var res; var idLength; var idPattern = /^[a-zA-Z]+[a-zA-Z0-9]*$/; res = this.isEmpty(id); if (res == true) return false; idLength = id.length; if (idLength < 5 || idLength > 20) return false; return idPattern.test(id); } /*** }}} ***/ /*** fc_isValidName(name) {{{ ***/ function fc_isValidName(name) { var namePattern = /[a-zA-Z0-9]/; return namePattern.test(name); } /*** }}} ***/ /*** fc_isValidSpaceName(name) {{{ ***/ function fc_isValidSpaceName(name) { var namePattern = /[^\s]+[\s]+[^\s]+/; return namePattern.test(name); } /*** }}} ***/ /*** fc_isValidPassword(password) {{{ ***/ function fc_isValidPassword(password) { var res; var passwordLength; res = this.isEmpty(password); if (res == true) return false; passwordLength = password.length; if (passwordLength < 5 || passwordLength > 40) return false; return true; } /*** }}} ***/ /*** fc_isValidEmail(Email) {{{ ***/ function fc_isValidEmail(email) { var emailPattern = /^([a-zA-Z0-9_\-\.\+]+)@[a-z0-9][a-z0-9\.\-]+[a-z0-9]+$/ return emailPattern.test(email); } /*** }}} ***/ /*** fc_isValidEmailLength(Email) {{{ ***/ function fc_isValidEmailLength(email) { if (email.length >= 50) return false; else return true; } /*** }}} ***/ /*** fc_isValidMXRank() {{{ ***/ function fc_isValidMXRank(rank) { if (isNaN(rank) == true) { return false; } if (rank < 0 || rank > 32767) { return false; } return true } /*** }}} ***/ /*** fc_isValidMailForward(userDomain, newEmail) {{{ ***/ function fc_isValidMailForward(userDomain, newEmail) { var mailForwardPattern = new RegExp('@'+userDomain, "i"); return mailForwardPattern.test(newEmail); } /*** }}} ***/ /*** fc_isPrivateIP(ip) {{{ ***/ function fc_isPrivateIP(ip) { ip = trim(ip); if (ip == '255.255.255.255') return false; var pattern = /^(10\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5]))))|^(172\.((((1[[6-9])|(2[0-9])|(3[0-1])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))))|^(192\.168\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5]))))|^(127\.0\.0\.1)$/; return pattern.test(ip); } /*** }}} ***/ /*** fc_isValidAuthcode(authcode) {{{ ***/ function fc_isValidAuthcode(authcode) { var res; var authcodeLength; var authcodePattern = /^[a-zA-Z0-9]*$/; res = this.isEmpty(authcode); if (res == true) return false; authcodeLength = authcode.length; if (authcodeLength < 5 || authcodeLength > 40) return false; return authcodePattern.test(authcode); } /*** }}} ***/ /*** fc_isValidOfflineMsg() {{{ ***/ function fc_isValidOfflineMsg(message) { message = trim(message); var pattern = /