Eyes Of Siche
Guest book

숫자 혹은 특수문자 제어 폼

이런 저런 폼에 특수문자를 제외 한다든지.. 아니면 숫자만 받아야 한다든지 할때 스크립트이다.

<script type="text/javascript">
function strCheck(frm){
    var strCheck1 = /[^0-9]/;

    if(strCheck1.test(frm.str.value))     {         alert("숫자만 사용할수 있습니다.");         frm.str.value='';         frm.str.focus();         return false;     }     else     {         alert("성공");         return false;     } } </script> <form onsubmit="return strCheck(this)"> <input type="text" name="str" /> <input type="submit" value="ok" /> </form>


var strCheck1 = /[^0-9]/;
이놈이 정규식이라는 놈이다. 0-9 까지의 문자를 표현 한 것이다.
만약 숫자가 아닌 놈이 들어 가면 해당 input을 지우고 포커스를 맞춘다.
<SCRIPT type="text/javascript">
function strCheck(frm){
    var strCheck2 = /[^a-zA-Z0-9_]/;

    if(strCheck2.test(frm.str.value))     {         alert("특수문자는 노~");         frm.str.value='';         frm.str.focus();         return false;     }     else     {         alert("성공");         return false;     } } </script> <form onsubmit="return strCheck(this)"> <input type="text" name="str" /> <input type="submit" value="ok" /> </form>


var strCheck2 = /[^a-zA-Z0-9_]/;
모든 문자를 나타낸 것이다. 하지만 앞에 ^ 이놈은 NOT 이다.
고로 저놈들을 제외한 문자는 특수 문자인 것이다.
이것 역시 특수문자가 들어 갔을때 해당 input을 지우고 포커스를 맞춘다.

Posted by siche

2007/01/01 00:02 2007/01/01 00:02
,
Response
No Trackback , No Comment
RSS
http://eos.pe.kr/rss/response/44

Trackback URL : http://eos.pe.kr/trackback/44

Leave a comment
[로그인][오픈아이디란?]
블로그 이미지

안돼는 것은 없다.. 항상 방법이 문제일 뿐이다.. 그 방법을 찾기 위해서는 노력할 뿐이다.. - siche

Archives

Recent Trackbacks

Calendar

«   2013/05   »
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  

Site Stats

Total hits:
813783
Today:
222
Yesterday:
304