javascript/typescript正規表現:中国語かどうか/英語かどうか

1253 ワード

private static chineseReg:RegExp;
	/**
	 *     
	 * 
	 */
	public static IsChinese(s:string):boolean
	{
		if(!this.chineseReg)
			this.chineseReg = new RegExp('^[\u4E00-\u9FFF]+$');
		if(!this.chineseReg.test(s))
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	private static chineseEnglishReg:RegExp;
	/**
	 *         
	 * 
	 */
	public static IsChineseOrEnglish(s:string):boolean
	{
		if(!this.chineseEnglishReg)
			this.chineseEnglishReg = new RegExp('^[a-zA-Z\u4E00-\u9FFF]+$');
		if(!this.chineseEnglishReg.test(s))
		{
			return false;
		}
		else
		{
			return true;
		}
	}


private static wholeNumberReg:RegExp;
	/**
	 *     
	 *
	 */
	public static IsWholeNumber(s:string):boolean
	{
		if(!this.wholeNumberReg)
			this.wholeNumberReg = new RegExp('^[\-0-9][0-9]*(.[0-9]+)?)$');
		if(!this.wholeNumberReg.test(s))
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	private static positiveIntergerReg:RegExp;
	/**
	 *    
	 *
	 */
	public static IsPositiveInteger(s:string):boolean
	{
		if(!this.positiveIntergerReg)
			this.positiveIntergerReg = new RegExp('^[0-9]*$');
		if(!this.positiveIntergerReg.test(s))
		{
			return false;
		}
		else
		{
			return true;
		}
	}