0
我添加了基因敲除驗證,但它似乎拋出了我放在該領域的所有東西:a,1,?等 - 唯一有效的工作是讓該字段爲空。我正在使用ko驗證庫,並使用模式規則對其進行了擴展。基因敲除驗證模式拋出一切錯誤
柯模板:
<script type="text/html" id="solutionRowTemplate">
<tr>
<td>
<input type="text" class="whole" data-bind="value: firstWhole, valueUpdate: 'afterkeydown'" />
</td>
</tr>
</script>
柯視圖模型:
<script type="text/javascript">
var solutionData = @Html.Raw(new JavaScriptSerializer().Serialize(Model.SolutionList));
function SolutionModel(firstWhole) {
this.firstWhole = ko.observable(firstWhole);
}
var viewModel = {
solutions: ko.observableArray(ko.utils.arrayMap(solutionData, function (item) {
var model = new SolutionModel(item.FirstWhole);
model.firstWhole.extend({ pattern: '^[a-z0-9].$' });
return model;
})),
addSolution: function() {
this.solutions.push(new SolutionModel('', '', '', '', '', '', '', '', '', '', '', ''));
},
};
ko.applyBindings(viewModel);
</script>
不會感到驚訝,如果它錯了,我如何添加擴展...
謝謝, -rob
d-oh,正則表達式問題,而不是ko驗證問題!猜猜我只需要另一雙眼睛。擺脫了點,現在它接受我需要的 - 現在使用這種模式:'^ [0-9 +] | \\?$'(只有任何數字和問號) –