I implemented a logic that checks whether the phone number is valid. However, it's not checking if the number should be only 10 digits.
self.validateContactInfo = function () {
let messages = [];
let regex = '^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}$';
let phone = self.phone.peek();
if (!phome && !phone.match(regex)) {
messages.push("Please enter valid phone number");
}
if (messages.length != 0) {
puDialogV2.showDialog($('.body-content'), "Error", messages, self, function () { return; });
throw new Error(messages);
}
}
<div class="contactItem">\
<label style="padding:6px" >Home phone</label>\
<input class="form-control" type="text" data-bind="textInput: Phone" /> \
<div class="contactSms" data-bind="if: smsNotificationFeatureEnabled, css: { hasInfoPopup: !smsNotificationFeatureEnabled() }">\
</div>\
</div>\
With the above code, if I leave the phone number field black or enter any alphabetic character, it throws an error. But If I enter 12 digit number it does not. For example, if I enter 71356878901212, it does not throw any error