dijit ValidationTextBox如何添加最小长度和最大长度

dijit ValidationTextBox how to add minlength and maxlength

我想知道如何(通过简单的工作示例)将 maxlengthminlength 添加到由

生成的输入标签
dijit/form/ValidationTextBox

所需输出示例:

<input maxlength="10" minlength="2" class="dijitReset dijitInputInner" data-dojo-attach-point="textbox,focusNode" autocomplete="off" name="title" type="text" tabindex="0" id="Image-1-title-LabelValidationTextBox" aria-required="undefined" value="Title text for image Image-1" aria-invalid="false">

使用正则表达式约束尝试这个例子

<input type="text" value="someTestString" required="true"
data-dojo-type="dijit/form/ValidationTextBox"
data-dojo-props="regExp: '[a-zA-Z0-9$%!_]{2,10}', invalidMessage: 'The value must be at least 2 character and maximum 10'" />

这是另一个解决方案:

registry.byId("validationTextBox").validator = function(value, constraints) {
    if(value) {
        return value.length >= 2 && value.length <= 10;
    }
    return true;
}

ValidationTextBox 具有属性 minLength 和 maxLength。它们以声明的方式用于以下原因。

  <input  data-dojo-type="dijit/form/ValidationTextBox"
            data-dojo-props="required:true,
                            maxLength:5,
                            minLength:2"
                            type="text" 
                            name="exmaple" />