자바스크립트 함수들...
컨텐츠 정보
- 19,605 조회
- 1 추천
- 목록
본문
/******************************
Document info
Auth : RedCat
Project :
Location : /common/jscript
Filename : Global.js
Update : 2004-02-16
Comment :
******************************/
if (document.layers){
var wb = 'ns4';
}
else if (document.all){
var wb = 'ie';
}
else if (document.getElementById){
var wb = 'ns6';
}
//숫자,알파벳만//////////////////////////////////////////////
function ChkAlNum(strValue) {
for(var i=0; i<strValue.length;i ++) {
var strCh = strValue.charAt(i).toUpperCase();
if(strCh >="A" && strCh <="Z") continue;
if(strCh >="0" && strCh <="9") continue;
if(strCh =" ") continue;
return false;
}
}
//공백체크////////////////////////////////////////////////////
function ChkSpace(strValue) {
if (strValue.indexOf(" ")>=0) {
return true;
}else {
return false;
}
}
//한글체크////////////////////////////////////////////////////
function ChkHan(strValue) {
for(i=0;i<strValue.length;i++) {
var a=strValue.charCodeAt(i);
if (a > 128) {
return true;
}else{
return false;
}
}
}
//숫자체크////////////////////////////////////////////////////
function ChkNum(x){
var x;
var anum=/(^\\d+$)|(^\\d+\\.\\d+$)/
if (anum.test(x))
return true;
else{
return false;
}
}
//주민등록번호체크//////////////////////////////////////////
function ChkJumin(str_jumin1,str_jumin2) {
errfound = false;
var str_jumin1;
var str_jumin2;
var checkImg='';
var i3=0
for (var i=0;i<str_jumin1.length;i++) {
var ch1 = str_jumin1.substring(i,i+1);
if (ch1<'0' || ch1>'9') { i3=i3+1 }
}
if ((str_jumin1 == '') || ( i3 != 0 )) {
return false;
}
var i4=0
for (var i=0;i<str_jumin2.length;i++) {
var ch1 = str_jumin2.substring(i,i+1);
if (ch1<'0' || ch1>'9') { i4=i4+1 }
}
if ((str_jumin2 == '') || ( i4 != 0 )) {
return false;
}
if(str_jumin1.substring(0,1) < 4) {
return false;
}
if(str_jumin2.substring(0,1) > 2) {
return false;
}
if((str_jumin1.length > 7) || (str_jumin2.length > 8)) {
return false;
}
if ((str_jumin1 == '72') || ( str_jumin2 == '18')) {
return false;
}
var f1=str_jumin1.substring(0,1)
var f2=str_jumin1.substring(1,2)
var f3=str_jumin1.substring(2,3)
var f4=str_jumin1.substring(3,4)
var f5=str_jumin1.substring(4,5)
var f6=str_jumin1.substring(5,6)
var hap=f1*2+f2*3+f3*4+f4*5+f5*6+f6*7
var l1=str_jumin2.substring(0,1)
var l2=str_jumin2.substring(1,2)
var l3=str_jumin2.substring(2,3)
var l4=str_jumin2.substring(3,4)
var l5=str_jumin2.substring(4,5)
var l6=str_jumin2.substring(5,6)
var l7=str_jumin2.substring(6,7)
hap=hap+l1*8+l2*9+l3*2+l4*3+l5*4+l6*5
hap=hap%11
hap=11-hap
hap=hap%10
if (hap != l7) {
return false;
}
var i9=0
if (!errfound)
return true;
}
//이메일체크/////////////////////////////////////////
function ChkMail(strValue) {
if(ChkSpace(strValue)){
//alert ("E메일 주소에서 공란을 빼주십시오");
return false;
}else if (strValue.indexOf("/")!=-1 || strValue.indexOf(";") !=-1 || ChkHan(strValue)) {
//alert("E-Mail형식이 잘못되었습니다.\\n 다시한번 확인바랍니다.");
return false;
}else if ((strValue.length != 0) && (strValue.search(/(\\S+)@(\\S+)\\.(\\S+)/) == -1)) {
//alert("E-Mail형식이 잘못되었습니다..\\n 다시한번 확인바랍니다.");
return false;
}else{
return true;
}
}
//새창열기/////////////////////////////////////////////
function OpenWindow(url,target,width,height,scroll,toolbar,resiz,stat) {
toolbar = toolbar?toolbar:"no";
resiz = resiz?resiz:"no";
stat = stat?stat:"no";
scroll = scroll?scroll:"yes";
window.open(url,target,'width=' + width + ',height=' + height + ',toolbar=' + toolbar + ',resizable='+resiz+',scrollbars='+scroll+',status='+stat);
}
//trim//////////////////////////////////////////////////
function trim(ment){
var start;
var end;
for(i=0;i<ment.length;i++){
mentcnt = ment.substring(i,i+1);
if (mentcnt != ' '){
start=i;
break;
}
}
for(i=ment.length - 1;i > -1; i--){
mentcnt = ment.substring(i,i+1);
if (mentcnt != ' ') {
end=i;
break
}
}
str = ment.substring(start,end+1);
if (str == ' ')
{
str = '';
}
return str;
}
// 콤마 넣기 //////////////////////////////////////////
function SetComma(frm) {
var rtn = "";
var val = "";
var j = 0;
x = frm.value.length;
for(i=x; i>0; i--) {
if(frm.value.substring(i,i-1) != ",") {
val = frm.value.substring(i,i-1)+val;
}
}
x = val.length;
for(i=x; i>0; i--) {
if(j%3 == 0 && j!=0) {
rtn = val.substring(i,i-1)+","+rtn;
}else {
rtn = val.substring(i,i-1)+rtn;
}
j++;
}
frm.value = rtn;
}
// 콤마 삭제 ////////////////////////////////////////
function SrtipComma(frm){
var val='';
x = frm.length;
for(i=x; i>0; i--) {
if(frm.substring(i,i-1) != ",") {
val = frm.substring(i,i-1)+val;
}
}
return val;
}
// 문서내 id = img_in_content 인 이미지 크기 조절 ///////////////////////
function ReSetImgSize(mxw,mxh) {
mxw = mxw?mxw:400;
mxh = mxh?mxh:300;
var maxheight = mxh;
var maxwidth = mxw;
var img_properties = new Array();
if(wb == 'ns6') {
var imgs = document.getElementById[img_in_content];
} else if (wb == 'ie') {
var imgs = document.all.img_in_content;
} else if (wb == 'ns4') {
var imgs = document.layers[img_in_content];
} else {
return false;
}
if (imgs.length == 0) {
return false;
}
for(i=0; i<imgs.length; i++) {
if(maxwidth > 0 && maxheight >0) {
img_properties[0] = imgs[i].width;
img_properties[1] = imgs[i].height;
if(img_properties[0]>maxwidth||img_properties[1]>maxheight) {
height = (maxwidth*img_properties[1])/img_properties[0];
width = maxwidth;
if(height > maxheight) {
width = (maxheight*img_properties[0])/img_properties[1];
height = maxheight;
}
}else {
height = img_properties[1];
width = img_properties[0];
}
}else {
height = img_properties[1];
width = img_properties[0];
}
imgs[i].width = width;
imgs[i].height = height;
imgs[i].style.cursor="hand";
}
}
Document info
Auth : RedCat
Project :
Location : /common/jscript
Filename : Global.js
Update : 2004-02-16
Comment :
******************************/
if (document.layers){
var wb = 'ns4';
}
else if (document.all){
var wb = 'ie';
}
else if (document.getElementById){
var wb = 'ns6';
}
//숫자,알파벳만//////////////////////////////////////////////
function ChkAlNum(strValue) {
for(var i=0; i<strValue.length;i ++) {
var strCh = strValue.charAt(i).toUpperCase();
if(strCh >="A" && strCh <="Z") continue;
if(strCh >="0" && strCh <="9") continue;
if(strCh =" ") continue;
return false;
}
}
//공백체크////////////////////////////////////////////////////
function ChkSpace(strValue) {
if (strValue.indexOf(" ")>=0) {
return true;
}else {
return false;
}
}
//한글체크////////////////////////////////////////////////////
function ChkHan(strValue) {
for(i=0;i<strValue.length;i++) {
var a=strValue.charCodeAt(i);
if (a > 128) {
return true;
}else{
return false;
}
}
}
//숫자체크////////////////////////////////////////////////////
function ChkNum(x){
var x;
var anum=/(^\\d+$)|(^\\d+\\.\\d+$)/
if (anum.test(x))
return true;
else{
return false;
}
}
//주민등록번호체크//////////////////////////////////////////
function ChkJumin(str_jumin1,str_jumin2) {
errfound = false;
var str_jumin1;
var str_jumin2;
var checkImg='';
var i3=0
for (var i=0;i<str_jumin1.length;i++) {
var ch1 = str_jumin1.substring(i,i+1);
if (ch1<'0' || ch1>'9') { i3=i3+1 }
}
if ((str_jumin1 == '') || ( i3 != 0 )) {
return false;
}
var i4=0
for (var i=0;i<str_jumin2.length;i++) {
var ch1 = str_jumin2.substring(i,i+1);
if (ch1<'0' || ch1>'9') { i4=i4+1 }
}
if ((str_jumin2 == '') || ( i4 != 0 )) {
return false;
}
if(str_jumin1.substring(0,1) < 4) {
return false;
}
if(str_jumin2.substring(0,1) > 2) {
return false;
}
if((str_jumin1.length > 7) || (str_jumin2.length > 8)) {
return false;
}
if ((str_jumin1 == '72') || ( str_jumin2 == '18')) {
return false;
}
var f1=str_jumin1.substring(0,1)
var f2=str_jumin1.substring(1,2)
var f3=str_jumin1.substring(2,3)
var f4=str_jumin1.substring(3,4)
var f5=str_jumin1.substring(4,5)
var f6=str_jumin1.substring(5,6)
var hap=f1*2+f2*3+f3*4+f4*5+f5*6+f6*7
var l1=str_jumin2.substring(0,1)
var l2=str_jumin2.substring(1,2)
var l3=str_jumin2.substring(2,3)
var l4=str_jumin2.substring(3,4)
var l5=str_jumin2.substring(4,5)
var l6=str_jumin2.substring(5,6)
var l7=str_jumin2.substring(6,7)
hap=hap+l1*8+l2*9+l3*2+l4*3+l5*4+l6*5
hap=hap%11
hap=11-hap
hap=hap%10
if (hap != l7) {
return false;
}
var i9=0
if (!errfound)
return true;
}
//이메일체크/////////////////////////////////////////
function ChkMail(strValue) {
if(ChkSpace(strValue)){
//alert ("E메일 주소에서 공란을 빼주십시오");
return false;
}else if (strValue.indexOf("/")!=-1 || strValue.indexOf(";") !=-1 || ChkHan(strValue)) {
//alert("E-Mail형식이 잘못되었습니다.\\n 다시한번 확인바랍니다.");
return false;
}else if ((strValue.length != 0) && (strValue.search(/(\\S+)@(\\S+)\\.(\\S+)/) == -1)) {
//alert("E-Mail형식이 잘못되었습니다..\\n 다시한번 확인바랍니다.");
return false;
}else{
return true;
}
}
//새창열기/////////////////////////////////////////////
function OpenWindow(url,target,width,height,scroll,toolbar,resiz,stat) {
toolbar = toolbar?toolbar:"no";
resiz = resiz?resiz:"no";
stat = stat?stat:"no";
scroll = scroll?scroll:"yes";
window.open(url,target,'width=' + width + ',height=' + height + ',toolbar=' + toolbar + ',resizable='+resiz+',scrollbars='+scroll+',status='+stat);
}
//trim//////////////////////////////////////////////////
function trim(ment){
var start;
var end;
for(i=0;i<ment.length;i++){
mentcnt = ment.substring(i,i+1);
if (mentcnt != ' '){
start=i;
break;
}
}
for(i=ment.length - 1;i > -1; i--){
mentcnt = ment.substring(i,i+1);
if (mentcnt != ' ') {
end=i;
break
}
}
str = ment.substring(start,end+1);
if (str == ' ')
{
str = '';
}
return str;
}
// 콤마 넣기 //////////////////////////////////////////
function SetComma(frm) {
var rtn = "";
var val = "";
var j = 0;
x = frm.value.length;
for(i=x; i>0; i--) {
if(frm.value.substring(i,i-1) != ",") {
val = frm.value.substring(i,i-1)+val;
}
}
x = val.length;
for(i=x; i>0; i--) {
if(j%3 == 0 && j!=0) {
rtn = val.substring(i,i-1)+","+rtn;
}else {
rtn = val.substring(i,i-1)+rtn;
}
j++;
}
frm.value = rtn;
}
// 콤마 삭제 ////////////////////////////////////////
function SrtipComma(frm){
var val='';
x = frm.length;
for(i=x; i>0; i--) {
if(frm.substring(i,i-1) != ",") {
val = frm.substring(i,i-1)+val;
}
}
return val;
}
// 문서내 id = img_in_content 인 이미지 크기 조절 ///////////////////////
function ReSetImgSize(mxw,mxh) {
mxw = mxw?mxw:400;
mxh = mxh?mxh:300;
var maxheight = mxh;
var maxwidth = mxw;
var img_properties = new Array();
if(wb == 'ns6') {
var imgs = document.getElementById[img_in_content];
} else if (wb == 'ie') {
var imgs = document.all.img_in_content;
} else if (wb == 'ns4') {
var imgs = document.layers[img_in_content];
} else {
return false;
}
if (imgs.length == 0) {
return false;
}
for(i=0; i<imgs.length; i++) {
if(maxwidth > 0 && maxheight >0) {
img_properties[0] = imgs[i].width;
img_properties[1] = imgs[i].height;
if(img_properties[0]>maxwidth||img_properties[1]>maxheight) {
height = (maxwidth*img_properties[1])/img_properties[0];
width = maxwidth;
if(height > maxheight) {
width = (maxheight*img_properties[0])/img_properties[1];
height = maxheight;
}
}else {
height = img_properties[1];
width = img_properties[0];
}
}else {
height = img_properties[1];
width = img_properties[0];
}
imgs[i].width = width;
imgs[i].height = height;
imgs[i].style.cursor="hand";
}
}
관련자료
-
링크
댓글 0
등록된 댓글이 없습니다.