timevalidator.lzx
<library>
<include href="basevalidator.lzx"/>
<class name="timevalidator" extends="basevalidator">
<attribute name="format" type="string" value="hh:mi:ss
"/>
<attribute name="separator" type="string" value=":
"/>
<attribute name="incongruentSeparatorErrorstring" type="string" value="Warning! Two different separators are defined in format and separator attribute
"/>
<attribute name="invalidformatErrorstring" type="string" value="Please input the time in a valid format
"/>
<attribute name="invalidHourErrorstring" type="string" value="Please enter hour between 0 and 23
"/>
<attribute name="invalidMinutesErrorstring" type="string" value="Please enter minutes between 0 and 59
"/>
<attribute name="invalidSecondsErrorstring" type="string" value="Please enter seconds between 0 and 59
"/>
<attribute name="invalidSeparatorErrorstring" type="string" value="Please enter a valid separator
"/>
<method name="doValidation" args="val">
var valtext = this.getValueText(val);
// First of all I check that "format" and "separator" attributes have the same separator.
if(!this.isCongruentSeparator()){
this.setErrorstring(this.incongruentSeparatorErrorstring);
return false;
}
if(this.required && valtext.length < 1){
this.setErrorstring(this.requiredErrorstring);
return false;
}
if(valtext != ""){
if(!this.isValidLength(valtext)){
this.setErrorstring(this.invalidformatErrorstring + " " + this.format);
return false;
}
if(!this.isValidHour(valtext)){
this.setErrorstring(this.invalidHourErrorstring);
return false;
}
if(!this.isValidMinutes(valtext)){
this.setErrorstring(this.invalidMinutesErrorstring);
return false;
}
if(!this.isValidSeconds(valtext)){
this.setErrorstring(this.invalidSecondsErrorstring);
return false;
}
if(!this.isValidSeparator(valtext)){
this.setErrorstring(this.invalidSeparatorErrorstring + " " + this.separator);
return false;
}
}
this.setErrorstring("");
return true;
</method>
<method name="isValidLength" args="value">
if(this.format.length == value.length)
return true;
else
return false;
</method>
<method name="isValidHour" args="value">
var hour = getHour(value);
if(isInt(hour)){
var intHour = parseInt(hour, 10);
if( -1 < intHour && intHour < 24)
return true;
}
return false;
</method>
<method name="isValidMinutes" args="value">
var minutes = getMinutes(value);
if(isInt(minutes)){
var intMinutes = parseInt(minutes, 10);
if(-1 < intMinutes && intMinutes < 60)
return true;
}
return false;
</method>
<method name="isValidSeconds" args="value">
var seconds = getSeconds(value);
if(isInt(seconds)){
var intSeconds = parseInt(seconds, 10);
if(-1 < intSeconds && intSeconds < 60)
return true;
}
return false;
</method>
<method name="isCongruentSeparator">
if (this.separator.length > 0){
if (this.format.indexOf(this.separator) == -1){
return false;
}
}
return true;
</method>
<method name="isValidSeparator" args="value">
if (this.separator.length > 0){
var i = 0;
while (i <= value.length){
var ls_subformat = this.format.substring(i, this.format.length);
var ls_subvalue = value.substring(i, value.length);
var idx = ls_subformat.indexOf(this.separator);
if (idx > 0){
if (ls_subvalue.substring(idx, idx+1) != this.separator && idx > 0){
return false;
}
i = i + idx + 1;
}
else{
return true;
}
i = i + 1;
}
}
return true;
</method>
<method name="isInt" args="value">
return ! isNaN(value);
</method>
<method name="getHour" args="value">
var idx = this.format.indexOf("hh");
return value.substring(idx, idx+2);
</method>
<method name="getMinutes" args="value">
var idx = this.format.indexOf("mi")
return value.substring(idx, idx+2);
</method>
<method name="getSeconds" args="value">
var idx = this.format.indexOf("ss")
return value.substring(idx, idx+2);
</method>
</class>
</library>
Cross References
Includes
Classes