/** * EUC-KR * °øÅë Æûüũ ¶óÀ̺귯¸® * required="value">, required="radio"> * option="hangul">, option="phone">, option="email"> * regexp="pattern"> */ function validate(form) { var regNum = /^[0-9]+$/; var regPhone = /^[0-9]{2,3}-[0-9]{3,4}-[0-9]{3,4}$/; var regMail = /^[_a-zA-Z0-9-\.-]+@[\._a-zA-Z0-9-]+\.[a-zA-Z]+$/; var regDomain = /^[\.a-zA-Z0-9-]+\.[a-zA-Z]+$/; var regAlpha = /^[a-zA-Z]+$/; var regHost = /^[a-zA-Z-]+$/; var regHangul = /[°¡-Èþ]/; var regHangulOnly = /^[°¡-Èþ ]*$/; var customRegexp; var regNickname = /^[a-zA-Z0-9°¡-Èþ]{3,12}/; for (i = 0; i < form.elements.length; i++ ) { var currEl = form.elements[i]; if (currEl.getAttribute("required") != null && currEl.getAttribute("required") != '' && ! currEl.disabled) { if (currEl.getAttribute("required") == "radio") { if (! isCheckedRadio(currEl)) { return do_error(currEl, "radio"); } } else { if (currEl.value == "") { return do_error(currEl); } } } if (currEl.getAttribute("option") != null && currEl.getAttribute("option") != '' && currEl.value != "") { if (currEl.getAttribute("option") == "email" && ! regMail.test(currEl.value)) { return do_error(currEl, "mail"); } if (currEl.getAttribute("option") == "phone" && ! regPhone.test(currEl.value)) { return do_error(currEl, "phone"); } if (currEl.getAttribute("option") == "hangul" && ! regHangul.test(currEl.value)) { return do_error(currEl, "hangul"); } if (currEl.getAttribute("option") == "number" && ! regNum.test(currEl.value)) { return do_error(currEl, "number"); } if (currEl.getAttribute("option") == "id" && ! checkId(currEl.value)) { return do_error(currEl, "id"); } if (currEl.getAttribute("option") == "nickname" && ! regNickname.test(currEl.value)) { return do_error(currEl, "nickname"); } if (currEl.getAttribute("option") == "password" && ! commonCheckPassword(currEl.value)) { return do_error(currEl, "password"); } } if (currEl.getAttribute("regexp") != null && currEl.getAttribute("regexp") != '' && currEl.getAttribute("required") != "notrequired") { customRegexp = eval("/" + currEl.getAttribute("regexp") + "/"); if (! customRegexp.test(currEl.value)) { return do_error(currEl, "regexp"); } } } return true; } function do_error(el, type) { name = (el.getAttribute("label")) ? el.getAttribute("label") : el.getAttribute("name"); switch (type) { case "mail": alert(name + "ÀÇ Çü½ÄÀÌ ¿Ã¹Ù¸£Áö ¾Ê½À´Ï´Ù"); break; case "phone": alert(name + "ÀÇ Çü½ÄÀÌ ¿Ã¹Ù¸£Áö ¾Ê½À´Ï´Ù"); break; case "hangul": alert(name + " Ç׸ñ¿¡ ÇѱÛÀÌ Æ÷ÇԵǾîÀÖÁö ¾Ê½À´Ï´Ù"); break; case "number": alert(name + " Ç׸ñ¿¡´Â ¼ýÀÚ¸¸ ÀÔ·ÂÇØ¾ß ÇÕ´Ï´Ù."); break; case "id": alert("3~16ÀÚ¸®ÀÇ ¿µ¹®ÀÚ, ¼ýÀÚ¸¸À¸·Î ÀÔ·ÂÇØÁֽʽÿÀ."); break; case "regexp": var ment = (el.getAttribute("ment")) ? el.getAttribute("ment") : ""; var message = name + "ÀÇ Çü½ÄÀÌ ¿Ã¹Ù¸£Áö ¾Ê½À´Ï´Ù."; if (ment) message += "\n" + ment; alert(message); break; case "radio": alert(name + " Áß Çϳª¸¦ ¼±ÅÃÇØ¾ß ÇÕ´Ï´Ù."); break; case "nickname": //alert(name + " Ç׸ñ¿¡´Â ÇѱÛ, ¿µ¹®ÀÚ, ¼ýÀÚ¸¸ ÀÔ·ÂÇØ¾ß ÇÕ´Ï´Ù.");//¿ø ¼Ò½º alert("´Ð³×ÀÓ Ç׸ñ¿¡´Â 3~12ÀÚÀÇ ÇѱÛ, ¿µ¹®ÀÚ, ¼ýÀÚ¸¸ ÀÔ·ÂÇØ¾ß ÇÕ´Ï´Ù.");//¹Ù²Û¼Ò½º break; case "password": alert("ºñ¹Ð¹øÈ£´Â ¿µ¹®+¼ýÀÚ+Ư¼ö¹®ÀÚ È¥ÇÕ 8ÀÚ~20ÀÚ·Î »ç¿ë °¡´ÉÇϸç,\nƯ¼ö¹®ÀÚ ! @ # $ & * ( ) - _ = + [ ] ; : ? . , ÀÌ¿ë °¡´ÉÇÕ´Ï´Ù.\n3ÀÚ ÀÌ»ó ¿¬¼Ó(123/abc) ¶Ç´Â Áߺ¹ ¹®ÀÚ, ¼ýÀÚ(111/aaa)´Â »ç¿ëÇÒ ¼ö ¾ø½À´Ï´Ù."); break; default: alert(name + " Ç׸ñÀ» ÀÔ·ÂÇØÁֽʽÿÀ."); break; } el.focus(); return false; } function checkId(str){ for(var i = 0 ; i < str.length ; i++) { if(!((str.charCodeAt(i) >= 65 && str.charCodeAt(i) <= 90) || (str.charCodeAt(i) >= 97 && str.charCodeAt(i) <= 122) || (str.charCodeAt(i) >= 48 && str.charCodeAt(i) <= 57))) { return false; } } return true; } function isCheckedRadio(radio) { var radios = eval("radio.form." + radio.name); var index = 0; for (index; index < radios.length; index++) { if (radios[index].checked) { return true; } } return false; } function checked_it(name,value) { var el = document.all.tags("input"); for (i = 0 ; i < el.length; i++) { if (el[i].name == name && el[i].value == value) { el[i].checked = true; } } } function selected_it(name,value) { var el = document.all.tags("select"); for (i = 0; i < el.length; i++) { if (el[i].name == name) { if (el[i].size > 1 && el[i].getAttribute("MULTIPLE") != null ) { for (k=0; k < value.length; k++) { alert(value[k]); for (j = 0; j < el[i].options.length; j++ ) { if (el[i].options[j].value == value[k]) el[i].selectedIndex[++x] = j; } } } else { for (j = 0; j < el[i].options.length; j++ ) { if (el[i].options[j].value == value) el[i].selectedIndex = j; } } } } } function enabled_it(name) { var arr = new Array("input", "select", "textarea"); for(k=0; k 128) ? 2 : 1; if (l > len) return str.substring(0,i) + "..."; } return str; } function cut_string(str, len, dot, printoption) { var strlen = str.length; var retstr; if (strlen < len) { if (printoption) { document.write(str); return; } else { return str; } } else { var templen = 0; var orglen = len; for(var i=0;i128 ) { templen++; } else { if(templen < orglen-2) { len = len + 0.5; } } } retstr = str.substring(0, len); if (dot) { retstr += ".."; } if (printoption) { document.write(retstr); return; } else { return retstr; } } } function validatePassword (pw, options) { var rtn = 0; // default options (allows any password) var o = { alpha: 0, /* lower + upper */ numeric: 0, special: 0, length: [0, Infinity], custom: [ /* regexes and/or functions */ ], badWords: [], badSequenceLength: 0, noQwertySequences: false, noSequential: false }; for (var property in options) o[property] = options[property]; var reAlpha = { alpha: /[A-Z]/gi }, reNumeric = { numeric: /[0-9]/g }, reSpecial = { special: /[\W_]/g }, rule, i; // enforce min/max length if (pw.length < o.length[0] || pw.length > o.length[1]) return 0; // enforce word ban (case insensitive) for (i = 0; i < o.badWords.length; i++) { if (pw.toLowerCase().indexOf(o.badWords[i].toLowerCase()) > -1) return 0; } // enforce the no sequential, identical characters rule if (o.noSequential && /([\S\s])\1{2,}/.test(pw)) return 0; // enforce alphanumeric/qwerty sequence ban rules if (o.badSequenceLength) { var lower = "abcdefghijklmnopqrstuvwxyz", upper = lower.toUpperCase(), numbers = "0123456789", qwerty = "qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM", start = o.badSequenceLength - 1, seq = "_" + pw.slice(0, start); for (i = start; i < pw.length; i++) { seq = seq.slice(1) + pw.charAt(i); if ( lower.indexOf(seq) > -1 || upper.indexOf(seq) > -1 || numbers.indexOf(seq) > -1 || (o.noQwertySequences && qwerty.indexOf(seq) > -1) ) { return 0; } } } // enforce custom regex/function rules for (i = 0; i < o.custom.length; i++) { rule = o.custom[i]; if (rule instanceof RegExp) { if (!rule.test(pw)) return 0; } else if (rule instanceof Function) { if (!rule(pw)) return 0; } } // enforce alpha rules for (rule in reAlpha) { if ((pw.match(reAlpha[rule]) || []).length >= o[rule]){ rtn++; break; } } // enforce numeric rules for (rule in reNumeric) { if ((pw.match(reNumeric[rule]) || []).length >= o[rule]){ rtn++; break; } } // enforce special rules for (rule in reSpecial) { if ((pw.match(reSpecial[rule]) || []).length >= o[rule]){ rtn++; break; } } if(rtn == 3){ for (rule in reSpecial) { if ((pw.match(reSpecial[rule]) || []).length >= 2){ rtn++; break; } } } // great success! return rtn; } function commonCheckPassword(password) { password = password.trim(); var passed = false; var rtn = 0; rtn = validatePassword(password, { length: [8, 20], alpha: 1, numeric: 1, special: 1, badWords: ["\`","\/","\\","\%","\"","|","\^","\{","\}","\<","\>"], badSequenceLength: 3, noQwertySequences: true, noSequential: true }); if(rtn > 1){ passed = true; } return passed; } function directCheckPassword(password) { password = password.trim(); var rtn = 0; var rtnTxt = ""; rtn = validatePassword(password, { length: [8, 20], alpha: 1, numeric: 1, special: 1, badWords: ["\`","\/","\\","\%","\"","\|","\^","\{","\}","\<","\>"], badSequenceLength: 3, noQwertySequences: true, noSequential: true }); if(rtn < 2){ rtnTxt = "red"; }else if(rtn == 2){ rtnTxt = "orange"; }else if(rtn == 3){ rtnTxt = "blue"; }else if(rtn > 3){ rtnTxt = "green"; }else{ rtnTxt = "red"; } return rtnTxt; }