Web Progreming
[ javascript ] 핸드폰번호 하이픈(-) 넣기
예감좋은
2013. 8. 9. 12:07
$('.phone_full_form').focus(function () {
var regExp = /^01([0|1|6|7|8|9]?)-?([0-9]{3,4})-?([0-9]{4})$/;
if(regExp.test($(this).val()) == false){
$(this).val('');
}
}).keydown(function(e) {
if( e.keyCode != '8' && e.keyCode != '46' ){
var input_text=$(this).val();
if( input_text.length == '3' || input_text.length == '8' ){
var add_hyphen=$(this).val()+'-';
$(this).val(add_hyphen);
}
}
}).focusout(function() {
var this_len=($(this).val()).length;
if( this_len <= '12' ){
//var hyphen_chg=/\d{3}-\d{3}-\d{4}$/g;
var str=$(this).val().replace(/[-]/gi,'');
var string=str.replace(/(^01[0|1|6|7|8|9]?)-?([0-9]{3,4})-?([0-9]{4})$/,"$1-$2-$3");
$(this).val(string);
}
});