0

我是 dojo 的新手,可以在以下 2 个字段验证示例中真正使用一些帮助。

在下面的 dijit.form.ValidationTextBox 字段示例中,指定验证器属性似乎覆盖了 regExp 的使用。(即该字段不再遵守 regExp 规则)。我如何让它两者兼得?

<input dojoType="dijit.form.ValidationTextBox"
type="password"
name="password2"
id="password2"
maxLength="50"
trim="true"
regExp="[\w]+"
required="true"
validator="return this.value == dijit.byId('password').value"
invalidMessage="Confirmation password must match password" />

我有另一个类似的示例,其中一个字段取决于另一个字段的值,但我的语法不正确。

<input dojoType="dijit.form.ValidationTextBox" type="text"
name="homePhone"
id="homePhone"
style="width:20%"
maxLength="10"
trim="true"
required="false"
regExp="[\d]{10}"
validator="return (dijit.byId('preferredContactMethod').value == "home") && (this.value != null)"
invalidMessage="Home phone required (ie. 9198887777)"
/>

4

1 回答 1

0

正确的; dijit.form.ValidationTextBox.prototype.validator() 的默认实现是将 this.value 与 this.regExp 匹配,并检查各种其他约束,如 this.required。查看源代码以了解它是如何完成的。如果您覆盖它,您将自行提供实现。您的实现可能会选择委托给原型方法,并使用您自己的测试在逻辑上“和”结果。我想你也可以覆盖 isValid。

于 2009-12-02T18:41:22.250 回答