// JavaScript Document
/**
使い方：
k = new StrChk(文字列);
k.isMail() とすればメールアドレスならばtrueが返る
k.isDay() とすれば日ならばtrueが返る
**/

function Validator(){
	this.alphabet = new RegExp(/\w*/);
	this.number = new RegExp(/\d*/);
	this.telnumber = new RegExp(/\d{1,4}[-]?\d{1,4}[-]?\d{1,4}/);
	this.mailaddress = new RegExp(/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/);
	this.day = new RegExp(/(3[0-1])|([1-2][1-9])|([0][1-9])|([1-9)])/);
	this.month = new RegExp(/(1[0-2])|([0][1-9])|([1-9])/);
	this.year = new RegExp(/\d{1,4}/);
	this.zipcode = new RegExp(/\d{3}\-\d{4}/);
	
	this.checker = function(str,chkreg){
		var succ = false;
		if(str==""){
			succ = false;
		}else{
			str.match(chkreg);
			if(str!=RegExp.lastMatch)
				succ = false;
			else
				succ = true;
		}
		return succ;
	}
	
	this.isTelNum = function(str){
		return this.checker(str,this.telnumber);		
	};
	
	this.isMail = function(str){
		if(this.checker(str,this.mailaddress)){
			if(str.length<=256){
				return true;
			}else{
				return false;
			}
		}else{
			return false;
		}
	};
	
	this.isDay = function(str){
		return this.checker(str,this.day);
	};
	
	this.isMonth = function(str){
		return this.checker(str,this.month);
	};
	
	this.isYear = function(str){
		return this.checker(str,this.year);
	};
	
	this.isZipcode = function(str){
		return this.checker(str,this.zipcode);
	}
}
