我有以下表格:
<form id="fromWiw" action="..." method="post">
...
<div class="controls span5 pull-left">
<label class="control-label" for="Quantity">@Resources.Quantity</label>
<input class="span12" id="Quantity" name="Quantity" type="number" min="0" value="0" required />
</div>
<div class="controls span5 pull-left">
<label class="control-label" for="Price">@Resources.Price</label>
<input class="span12" id="Price" name="Price" required />
</div>
...
</form>
对于验证部分,我有这个代码片段:
form.submit(function() {
form.validate(
{
rules: {
Quantity: { required: true, number: true},
Price: { required: true, number: true }
}
});
});
问题 验证工作正常,它正在检测价格和数量何时为空。但是,当价格输入包含非数值(例如文本)时,验证成功通过。验证适用于 Quantity 输入。我在这里做错了吗?