휴대폰번호 검사
본문
<SCRIPT LANGUAGE="Javascript">
<!--
function maskHp(obj) {
var str = obj.value;
if ( str ) {
//var pattern = /[^(ㄱ-힣)]|[-/\s]/g;
var RegNotNum = /[\D]/g;
var pattern = "";
var format = "";
// delete not number ㅋ
str = str.replace(RegNotNum,'');
//if( str.length < 4 ) return str;
if( str.length < 4 ) {
if( str.length == 3 ) {
format = "$1";
pattern = /(^01[\d]{0,1})/;
} else {
format = "$1";
pattern = /(^0[1]?[\d]{0,1})/;
}
} else if( str.length > 3 && str.length < 7 ) {
format = "$1-$2";
pattern = /(^01[\d]{1})([\d]+)/;
} else if(str.length == 7 ) {
format = "$1-$2";
pattern = /(^01[\d]{1})([\d]{4})/;
} else {
format = "$1-$2-$3";
pattern = /(^01[\d]{1})([\d]{4})([\d]+)/;
}
//while( pattern.test(str) ) {
if ( pattern.test(str) ) {
obj.value = str.replace(pattern, format);
} else {
obj.value = "";
}
}
}
function isHpFormat() {
var str = window.event.srcElement.value;
//alert ( str );
if ( window.event.propertyName == "value" && str ) {
var pattern = "";
str = str.replace(/[\D]/g,'');
if( str.length < 4 ) {
if( str.length == 3 ) pattern = /(^01[\d]{1})/;
else pattern = /(^0[1]?[\d]{0,1})/;
} else if( str.length > 3 && str.length < 7 ) {
pattern = /(^01[\d]{1})([\d]+)$/;
} else if(str.length == 7 ) {
pattern = /(^01[\d]{1})([\d]{4})/;
} else {
pattern = /(^01[\d]{1})([\d]{4})([\d]+)/;
}
if ( pattern.test(str) ) {
return true;
} else {
return false;
}
} else {
return true;
// undefined
}
}
//-->
</SCRIPT>
<input type='text' id='phon_num' value=''
size='14' maxlength='13'
onpropertychange='if(!isHpFormat()){alert("핸드폰 번호를 정확히 입력해주세요.");this.value="";}'
onkeyup ='maskHp(this);'
onkeydown='maskHp(this);' >
출처 : http://www.aircon1004.com/data/bbs/board.php?bo_table=pds1&wr_id=223
<!--
function maskHp(obj) {
var str = obj.value;
if ( str ) {
//var pattern = /[^(ㄱ-힣)]|[-/\s]/g;
var RegNotNum = /[\D]/g;
var pattern = "";
var format = "";
// delete not number ㅋ
str = str.replace(RegNotNum,'');
//if( str.length < 4 ) return str;
if( str.length < 4 ) {
if( str.length == 3 ) {
format = "$1";
pattern = /(^01[\d]{0,1})/;
} else {
format = "$1";
pattern = /(^0[1]?[\d]{0,1})/;
}
} else if( str.length > 3 && str.length < 7 ) {
format = "$1-$2";
pattern = /(^01[\d]{1})([\d]+)/;
} else if(str.length == 7 ) {
format = "$1-$2";
pattern = /(^01[\d]{1})([\d]{4})/;
} else {
format = "$1-$2-$3";
pattern = /(^01[\d]{1})([\d]{4})([\d]+)/;
}
//while( pattern.test(str) ) {
if ( pattern.test(str) ) {
obj.value = str.replace(pattern, format);
} else {
obj.value = "";
}
}
}
function isHpFormat() {
var str = window.event.srcElement.value;
//alert ( str );
if ( window.event.propertyName == "value" && str ) {
var pattern = "";
str = str.replace(/[\D]/g,'');
if( str.length < 4 ) {
if( str.length == 3 ) pattern = /(^01[\d]{1})/;
else pattern = /(^0[1]?[\d]{0,1})/;
} else if( str.length > 3 && str.length < 7 ) {
pattern = /(^01[\d]{1})([\d]+)$/;
} else if(str.length == 7 ) {
pattern = /(^01[\d]{1})([\d]{4})/;
} else {
pattern = /(^01[\d]{1})([\d]{4})([\d]+)/;
}
if ( pattern.test(str) ) {
return true;
} else {
return false;
}
} else {
return true;
// undefined
}
}
//-->
</SCRIPT>
<input type='text' id='phon_num' value=''
size='14' maxlength='13'
onpropertychange='if(!isHpFormat()){alert("핸드폰 번호를 정확히 입력해주세요.");this.value="";}'
onkeyup ='maskHp(this);'
onkeydown='maskHp(this);' >
출처 : http://www.aircon1004.com/data/bbs/board.php?bo_table=pds1&wr_id=223
관련링크
댓글목록
등록된 댓글이 없습니다.