JSFiddle - React, Tailwind, and code Playground
by Donal Devine
HTML
<script src="https://raw.github.com/ericmbarnard/Knockout-Validation/master/Src/knockout.validation.js"></script>
<input data-bind="value: ContactPhone">
JavaScript
ko.validation.init();
address().Zip.extend({
required: true,
pattern: {
message: 'Please specify a valid zip',
params: /(^\d{5}$)|(^\d{5}-\d{4}$)/
}
});
function VM() {
var self = this;
self.ContactPhone = ko.observable().extend({
required: true,
pattern: {
message: 'Invalid phone number.',
params: /^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$/
}
});
}
ko.applyBindings(window.v=new VM());