IT_Programming/JavaScript

아이디 비밀번호 공간체크 / 특수문자 체크

JJun ™ 2006. 4. 29. 08:22

<!-- 아이디,비밀번호 공백 / 특수문자 체크 -->
<SCRIPT language="JavaScript">
<!--
var Alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
var Digit = '1234567890'
var AlphaDigit = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'

function Tcheck(target, cmt, astr, lmin, lmax)
{
     var i
     var t = target.value

     if (t.length < lmin || t.length > lmax) {
             if (lmin == lmax) alert(cmt + '는 ' + lmin + ' 자 이어야 합니다');
                      else alert(cmt + '는 ' + lmin + ' ~ ' + lmax + ' 자 이내로 입력하셔야 합니다');
             target.focus()
             return true
     }
     if (astr.length > 1) {
             for (i=0; i<t.length; i++)
                     if(astr.indexOf(t.substring(i,i+1))<0) {
                             alert(cmt + '에 허용할 수 없는 문자가 입력되었습니다');
                             target.focus()
                             return true
                     }
     }
     return false
}

function InputCheck(f)
{
     var Alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
     var Digit = '1234567890'
 var AlphaDigit = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'

     if (Tcheck(f.strId, '아이디', AlphaDigit, 3, 10)) return false
     for (i =0;i < f.strId.value.length; i++) {
             ch = f.strId.value.charAt(i);
             if (ch == " ") {
                     alert("아이디에 공백이 있으면 안됩니다.");
                     f.strId.focus();
                     return(false);
             }
     }

     if (Tcheck(f.strPassword, '비밀번호', AlphaDigit, 4, 10)) return false

     return true
}

function submitform() {
 if (InputCheck(document.member_ac)) {
 document.member_ac.submit();
 }
}

function EnterCheck(){
  if(event.keyCode == 13){
     submitform();
 }
}

//-->
</script>

 

주의 :

form name = member_ac

아이디 input name = strId

비밀번호 input name = strPassword  라는 전제

 

 

<FORM METHOD=POST ACTION="login/login_ok.asp" NAME="member_ac">
                    <td bgcolor=#C8CCCB height=25 width=100% align=right>
    ID&nbsp;<input type="text" class="input" name="strId" size="15" maxlength="20">&nbsp;&nbsp;PW&nbsp;<input type="password" onkeydown="EnterCheck()" class="input" name="strPassword" size="15" maxlength="20">&nbsp;&nbsp;
                   <input type="button" class="input" value="로그인" onclick="javascript:submitform();">&nbsp;&nbsp;&nbsp;&nbsp;</td>
   </FORM>