checkdata.js 2.1 KB
function chkdate(years, months, days){
	months = months - 1;
	var dates = new Date(years, months, days);
	if (dates.getYear() < 1900) {
		if (years != dates.getYear() + 1900) {
			return false
		}
	} else {
		if (years != dates.getYear()) {
		return false
		}
	}

	if (months != dates.getMonth()) {
		return  false
	}

	if (days != dates.getDate()) {
		return false
	}
	return true;
}

function chrlengs(str){
	var  name2 = "";
	var  name3 = "";
	name2 = str.replace(/ /g,"");
	name3 = name2.replace(/ /g,"");
	return name3
}

function addzero(str){
	if (str != 0){
		if (str.length == 1){
			str = "0" + str;
		}
	}
	return str
}

//半角・全角を区別する
function charcount(str) {
	len = 0;
	str = escape(str);
	for (i = 0; i<str.length; i++, len++) {
		if (str.charAt(i) == "%") {
			if (str.charAt(++i) == "u") {
				i+= 3;
				len++;
			}
			i++;
		}
	}
return len;
} 

function datacheck(){
	var  fyear = document.event.fyear.value;
	var  fmon = document.event.fmon.value;
	var  fday = document.event.fday.value;
	var  name = document.event.eventname.value;
	var  hpadrs = document.event.hpadrs.value;
	var  tipword = document.event.tipword.value;

	//イベント名称の入力チェック
	name = chrlengs(name) 
	if (name.length == 0){
		alert("Please input the event name.");
	return false
	}
	if (charcount(name) > 200){
		alert("Please input the event name within 100 character ems.");
	return false
	}
	//不要なスペースの除去
	fyear = chrlengs(fyear);
	fmon = chrlengs(fmon);
	fday = chrlengs(fday);
	//一桁月日を二桁にする。
	fmon = addzero(fmon);
	fday = addzero(fday);

	//ホームページアドレスに全角が入力された場合エラーを出す
	if(hpadrs.match(/[^\x01-\x7E]/) ) {
		alert("Please input the home page address by a one-byte alphanumeric.");
	return false
	}
	//ホームページアドレスの文字数チェック
	if (charcount(hpadrs) > 500){
		alert("Please input the home page address within the one-byte 500 character.");
	return false
	}

	//メッセージの文字数チェック
	if (charcount(tipword) > 6000){
		alert("Please input a message within 3000 character ems.");
	return false
	}

	//登録チェック
	if(!(confirm ("Is it registered?"))){
		return false
	}
}