numbervalidator.lzx
<library>
<include href="basevalidator.lzx"/>
<class name="numbervalidator" extends="basevalidator">
<attribute name="minvalue" type="number" value="null
"/>
<attribute name="maxvalue" type="number" value="null
"/>
<attribute name="domain" type="string" value="real
"/>
<attribute name="trim" type="boolean" value="true
"/>
<attribute name="notnumberErrorstring" type="string" value="This field contains invalid characters.
"/>
<attribute name="notintErrorstring" type="string" value="Enter integer value.
"/>
<attribute name="toobigErrorstring" type="string" value="This number is too large.
"/>
<attribute name="toosmallErrorstring" type="string" value="This number is too small.
"/>
<method name="doValidation" args="val">
var valtext = getValueText(val);
if(required && valtext.length < 1){
this.setErrorstring(this.requiredErrorstring);
return false;
}
if(valtext != ""){
if(!isValidNumber(valtext)){
this.setErrorstring(this.notnumberErrorstring);
return false;
}
if(domain == "int" && !isInt(valtext)){
this.setErrorstring(this.notintErrorstring);
return false;
}
var valNum = parseFloat(valtext);
if(valNum < this.minvalue){
this.setErrorstring(this.toosmallErrorstring);
return false;
}
if(this.maxvalue < valNum){
this.setErrorstring(this.toobigErrorstring);
return false;
}
}
this.setErrorstring("");
return true;
</method>
<method name="isValidNumber" args="value">
return ! isNaN(value)
</method>
<method name="isInt" args="value">
if (value.toString().indexOf(".") < 0)
return true;
else
return false;
</method>
</class>
</library>
Cross References
Includes
Classes