numbervalidator.lzx

<!--
********************************************************
* [[validators/numbervalidator]]
* 2005/12/21 ver.2.0.0
* 2005/12/06 ver.1.0.1 add trim attribute [togawa manabu]
*
* 2005/11/06 ver.1.0.
* togawa manabu
* web:http://laszlo.jp
* mail:webmaster@laszlo.jp 
********************************************************
-->
<!---
      @topic Incubator
      @subtopic Validators
  -->
<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"/> <!-- real/int -->
        <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>
<!-- * X_LZ_COPYRIGHT_BEGIN ***************************************************
* Copyright 2006-2007 Laszlo Systems, Inc. All Rights Reserved.               *
* Use is subject to license terms.                                            *
* X_LZ_COPYRIGHT_END ****************************************************** -->
<!-- @LZX_VERSION@                                                         -->

Cross References

Includes

Classes