input_chk.js 5.86 KB
	//入力必須チェック
	function hissu_chk(pstrKomoku,pstrValue) {
		strTarget = pstrValue.replace(/[  ]/g, "");		//スペースカット
		if (strTarget=="") {
			alert(pstrKomoku + "が入力されていません")
			return false;
		}
	}
	
	//スクリプトチェック
	function script_chk(pstrKomoku,pstrValue){
		strTarget = pstrValue.replace(/[  ]/g, "");		//スペースカット
		data=strTarget.match(/[<,>]/g);					//パターンマッチ
		if (data) {
			alert(pstrKomoku + "の入力に不正な文字が含まれています")
			return false;
		}
	}

	//カナチェック
	function kana_chk(pstrKomoku,pstrValue) {
		data = pstrValue.match(/[^ア-ン,"ー","ヴ","ァ","ィ","ゥ","ェ","ォ","ャ","ュ","ョ","ヮ","ヰ","ヱ"]/g);
		if (data) {
			alert(pstrKomoku  + "の入力は全角カナを入力してください");
			return false;
		}
	}

	//全角チェック
	function zen_chk(pstrKomoku,pstrValue) {
	    var basic_len=("あ".length);
		for (i=0; i<pstrValue.length; i=i+basic_len){
			strCheck=pstrValue.charAt(i);
			if ((strCheck >="!" && strCheck <="~")||(strCheck >= "。" && strCheck <= "゚")){
				alert(pstrKomoku  + "の入力は全て全角文字です\n" + "全角文字を入力してください");
				return false;
			}
		}
	}

	//英数字チェック
	function eisu_chk(pstrKomoku,pstrValue) {
		eisudata=pstrValue.match(/[^abcdefghijklmnopqrstuvwxyz0123456789]/g);
		if (eisudata) {
			alert(pstrKomoku + "の入力は全て半角英数文字です\n" + "半角英数文字を入力してください");
			return false;
		}
	}

	//英字チェック
	function eiji_chk(pstrKomoku,pstrValue) {
		strTarget = pstrValue.replace(/[  ]/g, "");
		eijidata=strTarget.match(/[^a-z]/i);
		if (eijidata) {
			alert(pstrKomoku + "の入力は全て半角英字です\n" + "半角英字を入力してください");
			return false;
		}
	}

	//数値チェック
	function suchi_chk(pstrKomoku,pstrValue) {
		suchidata=pstrValue.match(/[^0-9]/g);			//パターンマッチ
		if (suchidata) {
			alert(pstrKomoku + "の入力は全て半角数字です\n" + "半角数字を入力してください");
			return false;
		}
	}

	//電話番号チェック
	function tel_chk(pstrKomoku,pstrValueSigai,pstrValueSinai,pstrValueKyoku) {
		strValueSigai = "" + pstrValueSigai
		strValueSinai = "" + pstrValueSinai
		strValueKyoku = "" + pstrValueKyoku
		if (strValueSigai + strValueSinai + strValueKyoku != "") {
			if(strValueSigai=="" || strValueSinai=="" || strValueKyoku==""){	//いずれかの入力なし
				alert(pstrKomoku + "の入力が不完全です");
				return false;
			}
		}
		if (strValueSigai != "") {
			if (suchi_chk(pstrKomoku,strValueSigai)==false) {		//数値チェック
				return false;
			}
		}
		if (strValueSinai != "") {
			if (suchi_chk(pstrKomoku,strValueSinai)==false) {		//数値チェック
				return false;
			}
		}
		if (strValueKyoku != "") {
			if (suchi_chk(pstrKomoku,strValueKyoku)==false) {		//数値チェック
				return false;
			}
		}
	}

	//郵便番号チェック
	function yuubin_chk(pstrMae,pstrAto) {
		strMae = "" + pstrMae.replace(/[  ]/g, "");	//スペースカット
		strAto = "" + pstrAto.replace(/[  ]/g, "");	//スペースカット
		if (strMae != "") {
			if (strMae.length != "3"){
				alert("郵便番号の入力が不正です");
				return false;
			}
			if (suchi_chk("郵便番号",strMae)==false) {
				return false;
			}
		}
		if (strAto != "") {
			if (strAto.length != "4"){
				alert("郵便番号の入力が不正です");
				return false;
			}
			if (strMae == "") {							//後ろのみ入力あり
				alert("郵便番号の入力が不正です");
				return false;
			}
			if (suchi_chk("郵便番号",strAto)==false) {
				return false;
			}
		}
	}

	//メールアドレスチェック
	function mailadr_chk(pacount,pdomain) {
		stracount = "" + pacount
		strdomain = "" + pdomain
		if (stracount + strdomain != "") {
			if(stracount=="" || strdomain==""){				//いずれかの入力なし
				alert("メールアドレスの入力が不正です");
				return false;
			}
		}
		acountdata=pacount.match(/[^A-Za-z0-9\-._.?.!.#.$.%.&.`.+.-.^.{.}]/g);
		domaindata=pdomain.match(/[^A-Za-z0-9\-._.?.!.#.$.%.&.`.+.-.^.{.}]/g);
		if (acountdata || domaindata) {
			alert("メールアドレスの入力が不正です");
			return false;
		}
	}
	
	//メールアドレスチェック
	function mailadr_chk2(pacount) {
		stracount = "" + pacount
		if (stracount != "") {
			if(stracount==""){				//入力なし
				alert("メールアドレスの入力が不正です");
				return false;
			}
		}
		acountdata=pacount.match(/[^A-Za-z0-9\-\/._.?.!.#.$.%.&.`.+.-.^.{.}]/g);
		if (acountdata) {
			alert("メールアドレスの入力が不正です");
			return false;
		}
	}

	//チェックボックスチェック
	function chkbox_chk(pstrKomoku,pobjChkbox,pintKosuu) {
		chkCnt = 0;
		for(i=0;i<=pintKosuu;i++){
			if (pobjchkbox[i].checked) {
				chkCnt++;
			}
		}
		if (chkCnt==0) {
			alert(pstrKomoku + "は1つ以上チェックしてください");
			return false;
		}
	}

	//URLチェック
	function url_chk(pstrValue) {
		data=pstrValue.match(/http:\/\//);
		if (!data) {
			alert("URLの入力が不正です");
			return false;
		}
	}

	//日付チェック
	function date_chk(pstrYear,pstrMonth,pstrDay) {
	
		if ((pstrMonth == "") && (pstrDay != "")){
			alert("日付を正しく入力してください");
			return false;
		}
		if ((pstrMonth != "") && (pstrDay == "")){
			alert("日付を正しく入力してください");
			return false;
		}
		if ((pstrYear.length != 4) && (pstrMonth != "") && (pstrDay != "")){
			alert("日付を正しく入力してください");
			return false;
		}
		if ((pstrYear.length == 4) && (pstrMonth == "") && (pstrDay == "")){
			alert("日付を正しく入力してください");
			return false;
		}
		
		if ((pstrMonth == 4) || (pstrMonth == 6) || (pstrMonth == 9) || (pstrMonth == 11)) {
			if (pstrDay == 31){
				alert("日付を正しく入力してください");
				return false;
			}
		}
		if (pstrMonth == 2){
			if (pstrDay == 31) {
				alert("日付を正しく入力してください");
				return false;
			}
			if (pstrDay == 30) {
				alert("日付を正しく入力してください");
				return false;
			}
			if (pstrDay == 29) {
				intData1 = pstrYear % 4;
				intData2 = pstrYear % 100;
				intData3 = pstrYear % 400;
				if (((intData1 == 0) && (intData2 != 0)) || (intData3 == 0)){
					}
				else{
					alert("日付を正しく入力してください");
					return false;
				}
			}
		}
	}