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

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

public class DateCombinParser extends AbstractValidator{

	public String validate(com.dev.energy.client.ui.InputUI inputUI) {
		if(inputUI.isEmpty()) {
			return null;
		}
		String value = inputUI.getValue().toString();
		boolean b = dateRegex(value);
		if (b) {
			return null;
		}
		return this.getHintMessage(inputUI);
	}
	
	private native boolean dateRegex(String str) /*-{
		var regex = "";

		if(str.indexOf("(") == -1) {
			regex = /^(\d{4}-\d{1,2}-\d{1,2})(((\,)(\d{4}-\d{1,2}-\d{1,2}))?)*$/;
		} else {
			regex = /^((\()(\d{4}-\d{1,2}-\d{1,2})?\,(\d{4}-\d{1,2}-\d{1,2})?(\)))((\,)((\()(\d{4}-\d{1,2}-\d{1,2})?\,(\d{4}-\d{1,2}-\d{1,2})?(\))))*$/;
		}
		return regex.test(str);
	}-*/;
	
}
