package com.dev.swms.client.ui.validate;

import com.dev.energy.client.validate.AbstractValidator;

public class  AbstractCombinParser extends AbstractValidator{
	
	private String regex;
	
	public String getRegex() {
		return regex;
	}

	public void setRegex(String regex) {
		this.regex = regex;
	}

	public String validate(com.dev.energy.client.ui.InputUI inputUI) {
		if(inputUI.isEmpty()) {
			return null;
		}
		String value = inputUI.getValue().toString();
		boolean b = validateWithRegex(value , getRegex());
		if (b) {
			return null;
		}
		return this.getHintMessage(inputUI);
	}
	
	public native boolean validateWithRegex(String str , String strRegex) /*-{
		var regex = "^\\s*[("+strRegex+"(\\s*,"+strRegex+")*)|(\\s*\\("+strRegex+",\\s*"+strRegex+"\\))]*$";
		var result = str.match(regex);
		if(result){
			return true;
		}
		return false;
	}-*/;
	
}
