I am trying to add validation for a phone number,
I need it to be required however I only want the pattern enforced if the country is the US This is what I have but it fails when I have Canada or any other country chosen
self.phone = ko.observable().extend({
required: {
onlyIf: function () {
return self.country() == "US";
}
},
pattern: {
message: 'Please enter a valid phone number in ###-###-#### format',
params: /^(\d{3}-\d{3}-\d{4})$/
}
});