Programming Learning Diary

Jquery를 이용한 정규식 사용 (한글만사용,영문만,숫자만사용)

페이지 정보

작성일 19-11-18 13:52

본문

keyup을이용해 input 의 내용이 바뀔때마다 체크해주는 원리를 이용했다. 긴말말고 코드 투척


                                <div class="c2">
                                    <label for="">성명<img src="" alt=""></label>
                                    <input type="text" placeholder="국문" name="wr_name" id="wr_name" required> 
                                    <input type="text" placeholder="영문" name="wr_name_e" id="wr_name_e"> 
                                </div>
                                <div>
                                    <label for="">휴대폰<img src="<?php echo G5_IMG_URL?>/require.png" alt=""></label>
                                    <input type="text" name="wr_phone" id="wr_phone" required>
                                </div>

<script>
                            $(document).ready(function(){
                                //영문검사
                                $("#wr_name_e").bind('focusin keyup'function(){
                                    var check_e = /^[A-Za-z]*$/;
                                    if(!check_e.test(this.value)){
                                        this.value="";
                                        alert('영문만 입력하세요');
                                    }
                                });
                                //한글검사
                                $("#wr_name").bind('focusin keyup'function(){
                                    var check = /[a-z0-9]|[ \[\]{}()<>?|`~!@#$%^&*-_+=,.;:\"'\\]/g;
                                    if(check.test(this.value)){
                                        this.value="";
                                        alert('한글만 입력하세요');
                                    }
                                });
//휴대전화검사
                                $("#wr_phone").bind('focusin keyup'function(){
                                    var check_p = /^[0-9]*$/;
                                    if(!check_p.test(this.value)){
                                        this.value="";
                                        alert('숫자만 입력하세요');
                                    }
                                });

                            });
</script> 




0e7aeba9455fd4d0faffa05baeda7393_1574052708_8986.png

0e7aeba9455fd4d0faffa05baeda7393_1574052709_0861.png

0e7aeba9455fd4d0faffa05baeda7393_1574053346_3291.png
 




댓글목록

등록된 댓글이 없습니다.