관리 메뉴

웹개발자의 기지개

[jQuery] 핸드폰번호 자동입력 (with 하이픈) 본문

jquery

[jQuery] 핸드폰번호 자동입력 (with 하이픈)

http://portfolio.wonpaper.net 2023. 12. 22. 20:51

 

위의 사진과 같이 키보드 키값을 각각 입력받으면서 (onkeyup)  자동 핸드폰번호를 입력받도록 하는 jquery  관련 소스이다.

 

1
2
3
4
5
6
7
8
9
10
11
<input type="text" style="width:220px;" class="input" id="mobileNum" name="mobileNum" maxlength="13" value=""/>
 
 
<script>
$("#mobileNum").keyup(function () {
    this.value = this.value
        .match(/\d*/g).join('')
        .match(/(\d{0,3})(\d{0,4})(\d{0,4})/).slice(1).join('-')
        .replace(/-*$/g, '');
});
</script>
cs

 

 

참고 : https://im-first-rate.tistory.com/138

Comments