IT_Programming/JavaScript

[자바스크립트] 숫자만 입력받기 , 한글입력노, 등등..

JJun ™ 2006. 4. 20. 13:20

http://blog.naver.com/ap570/120001986843 

 

======================================================================================


 
<SCRIPT LANGUAGE=javascript>
<!--
function check() {
        val = document.frm.pcs_num.value;
        new_val = '';
        for(i=0;i<val.length;i++) {
                char = val.substring(i,i+1);
                if (char < '0' || char > '9') {
                        alert('숫자만....');
                        document.frm.pcs_num.value = new_val;
                        return;
                } else {
                        new_val = new_val + char;
                }
        }
}
//-->
</SCRIPT>

<form name=frm>
<input type="text" name="pcs_num" maxlength="15" size="15" onkeyup="check();">
</form> 


=======================================================================


자바 스크립트에서 제공하는 함수를 사용하세요..

<script language="JavaScript">
<!--
function SubmitCheck(theForm)
{
        if (isNaN(theForm.name.value) || theForm.name.value == "")
        {
                alert("숫자만 입력하세요.");
                theForm.name.value = "";
                return false;
        }
        return true;
}
//-->
</script>

<form onsubmit="return SubmitCheck(this)">
<input type="text" name="name">
<input type=submit>
</form>


isNaN 함수는 입력값이 숫자인지 판별하는 함수 입니다.

 

=========================================================================

 

입력폼에서 한글을막는 스크립트

<script language=javascript>
<!--
        function isEng(str) {
                for(var i=0;i<str.length;i++){                
                        achar = str.charCodeAt(i);                 
                        if( achar > 255 ){
                                return false;
                        }
                }
                return true;
        }
         function sendit() {
                if (document.f1.USER_ID.value=="") {
                        alert("ID를 입력해 주세요.");
                        document.f1.USER_ID.focus();
                        return false;
                }
                if(!isEng(document.f1.USER_ID.value)){
                        alert('^^ ID는 한글을 사용할수 없습니다. ^^');
                        document.f1.USER_ID.focus();
                        return false;
                }
                  return true;
         }
//-->
</script>

 

=================================================================


입력란에 한글만 입력받기
<script language='javascript'>
function hangul()
{
if((event.keyCode < 12592) || (event.keyCode > 12687))
event.returnValue = false
}
</script>

<input type="text" name="Name" size="10" maxlength="15" class=ad onKeyPress="hangul();">

 

==========================================================