﻿//基本字串型態驗證規則物件
function StringPolicy( min_length, max_length , char_case , isBig5, allowEn)
{
	this.min_length= min_length;
	this.max_length= max_length;
	this.isBig5 = isBig5;
	this.allowEn=allowEn;
	this.char_case=char_case;
	this.checkPolicy = checkStringPolicy;
	this.message = ""
}
//基本字串型態驗證規則函式
function checkStringPolicy(value)
{
	if (value.constructor != String)
	{
		//提供錯誤訊息
		this.message = value + " 資料錯誤\n";
		return false;
	}
	//中文碼轉換成URLEncode表示計算長度
	if (this.isBig5)
	{
		value = escape(value);
		this.min_length= this.min_length*6;
		this.max_length= this.max_length*6;
		if ( (value.length%6) != 0 && this.allowEn == false) 
		{
			this.message = "不允許中英夾雜\n";
			return false;
		}
	}	
	if (value.length > 0)
	{
		if  ((value.length >= this.min_length) && ( value.length <= this.max_length))
		{
			this.message = "";
			return true;
		}
		else
		{
			//提供錯誤訊息
			this.message = " 長度錯誤【MAX=" + this.max_length + ",MIN="+ this.min_length +"】\n" ;
			return false;
		}
	}else{
		if( this.min_length > 0 )
		{
			//提供錯誤訊息
			this.message = "為必填欄位\n" ;
			return false;
		}	
	}
}