//숫자체크
function checkNum(obj){
if (obj == null || isNaN(obj.value)){
obj.focus();
return false;
}
return true;
}
//핸드폰 체크
function hpCheck(obj1,obj2,obj3){
var hp1 = obj1.value.replace(' ','');
var hp2 = obj2.value.replace(' ','');
var hp3 = obj3.value.replace(' ','');
var arr_hp2 = new Array(hp2.length);
var arr_hp3 = new Array(hp3.length);
var i=0;
for (i=0;i<hp2.length;i++){
arr_hp2[i] = hp2.charAt(i);
}
for (i=0;i<hp3.length;i++){
arr_hp3[i] = hp3.charAt(i);
}
if (!checkNum(obj2))
return false;
if (hp2.length <=2)
return false;
if (!checkNum(obj3))
return false;
if (hp3.length !=4)
return false;
if (hp1 == '010')
{
if (hp2.length == 4)
return true;
else
return false;
}else if (hp1 == '011' || hp1 == '016' || hp1 == '017' || hp1 == '018' || hp1 == '019'){
if (arr_hp2[0] == '1' || arr_hp2[0]=='9')
{
if (hp2.length == 4)
return true;
else
return false;
}else if (arr_hp2[0] == '0'){
return false;
}else{
if (hp2.length == 3)
return true;
else
return false;
}
}
return true;
}
//일반전화번호 체크
function phCheck(obj1,obj2,obj3){
var ph1 = obj1.value.replace(' ','');
var ph2 = obj2.value.replace(' ','');
var ph3 = obj3.value.replace(' ','');
var arr_ph1 = new Array(ph1.length);
var arr_ph2 = new Array(ph2.length);
var arr_ph3 = new Array(ph3.length);
for (i=0;i<ph1.length;i++){
arr_ph1[i] = ph1.charAt(i);
}
for (i=0;i<ph2.length;i++){
arr_ph2[i] = ph2.charAt(i);
}
for (i=0;i<ph3.length;i++){
arr_ph3[i] = ph3.charAt(i);
}
if (!checkNum(obj2))
return false;
if (ph2.length !=3 && ph2.length !=4)
return false;
if (!checkNum(obj3))
return false;
if (ph3.length !=4)
return false;
if (ph1 == '02')
{
if (arr_ph2[0] == '2'){
if (arr_ph2[1] == '0' || arr_ph2[1] == '1' || arr_ph2[1] == '2' || arr_ph2[1] == '6'){
if (ph2.length == 4)
return true;
else
return false;
}else return false;
}else if (arr_ph2[0] == '3'){
if (arr_ph2[1] == '5' || arr_ph2[1] == '8' || arr_ph2[1] == '9'){
if (ph2.length == 3)
return true;
else
return false;
}else if(arr_ph2[1] == '0'){
if (arr_ph2[2] == '1'){
if (ph2.length == 4)
return true;
else
return false;
}else{
if (ph2.length == 3)
return true;
else
return false;
}
}else if(arr_ph2[1] == '1'){
if (arr_ph2[2] == '4' || arr_ph2[2] == '5'){
if (ph2.length == 4)
return true;
else
return false;
}else{
if (ph2.length == 3)
return true;
else
return false;
}
}else if(arr_ph2[1] == '2'){
if (arr_ph2[2] == '1' || arr_ph2[2] == '7' || arr_ph2[2] == '8' || arr_ph2[2] == '9'){
if (ph2.length == 4)
return true;
else
return false;
}else{
if (ph2.length == 3)
return true;
else
return false;
}
}else if(arr_ph2[1] == '3'){
if (arr_ph2[2] == '9'){
if (ph2.length == 4)
return true;
else
return false;
}else{
if (ph2.length == 3)
return true;
else
return false;
}
}else if(arr_ph2[1] == '4'){
if (ph2.length == 4)
return true;
else
return false;
}else if(arr_ph2[1] == '6'){
if (arr_ph2[2] == '6' || arr_ph2[2] == '7'){
if (ph2.length == 4)
return true;
else
return false;
}else{
if (ph2.length == 3)
return true;
else
return false;
}
}else if(arr_ph2[1] == '7'){
if (arr_ph2[2] == '0' || arr_ph2[2] == '7' || arr_ph2[2] == '8' ){
if (ph2.length == 4)
return true;
else
return false;
}else{
if (ph2.length == 3)
return true;
else
return false;
}
}else{
return false;
}
}else if (arr_ph2[0] == '4' || arr_ph2[0] == '5' || arr_ph2[0] == '7' || arr_ph2[0] == '8' || arr_ph2[0] == '9'){
if (ph2.length == 3)
return true;
else
return false;
}else if (arr_ph2[0] == '6'){
if (ph2.length == 4)
return true;
else
return false;
}else{
return false;
}
}else if (ph1 == '031'){
if (arr_ph2[0]=='2' || arr_ph2[0]=='3' || arr_ph2[0]=='4' || arr_ph2[0]=='5' || arr_ph2[0]=='6' || arr_ph2[0]=='7' || arr_ph2[0]=='9'){
if (ph2.length == 3)
return true;
else
return false;
}else if (arr_ph2[0] == '8'){
if (arr_ph2[1] == '0'){
if (ph2.length == 4)
return true;
else
return false;
}else{
if (ph2.length == 3)
return true;
else
return false;
}
}else{
return false;
}
}else if (ph1 == '032' || ph1 == '033'){
if (arr_ph2[0] =='0' || arr_ph2[0] =='1')
return false;
else{
if (ph2.length == 3)
return true;
else
return false;
}
}else if (ph1.substring(0,2)=='04' || ph1.substring(0,2)=='05' || ph1.substring(0,2)=='06'){
if (arr_ph1[2] == '1' || arr_ph1[2] == '2' || arr_ph1[2] == '3' || arr_ph1[2] == '4' || arr_ph1[2] == '5'){
if (arr_ph2[0] == '0' || arr_ph2[0] == '1'){
return false;
}else{
if (ph2.length == 3)
return true;
else
return false;
}
}else{
return false;
}
}else if (ph1 =='050' || ph1 == '070'){
if (ph2.length == 4)
return true;
else
return false;
}else{
return false;
}
[출처] - http://jang8584.tistory.com/entry/%EC%9E%90%EB%B0%94%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8-%ED%95%B8%EB%93%9C%ED%8F%B0-%EB%B2%88%ED%98%B8-%EC%A0%84%ED%99%94%EB%B2%88%ED%98%B8-%EC%9C%A0%ED%9A%A8%EC%84%B1-%EC%B2%B4%ED%81%AC
'Carpe Programming > javascript' 카테고리의 다른 글
[tooltip]본문미리보기_마우스따라다님 (0) | 2011.11.16 |
---|---|
[HTML5 & Javascript & jQuery] Tip & Tech 강좌 모음 (0) | 2011.11.03 |
사업자등록번호 유효성 체크 (0) | 2011.10.18 |
e-mail 유효성 체크 (0) | 2011.10.18 |
정규표현식 (0) | 2011.10.18 |