Hello Everyone, PLEASE HELP!
I have project creating an Online Form, however, ran to a problem. I want to add the charector “-” in the middle of whatever they enter. it must be 9 digits. This field should allow a special character to be entered. Basically, the user can enter any special character into this field and it will append the “-”. For example, user can enter “12-3456789” and it will automatically display as “12345-6789”.
Java Script:
applicantAddressZipCode.subscribe(function (newValue) {
if (newValue != undefined && newValue != '') {
applicantAddressZipCode(formatZipCode(newValue));
var dataValue = String(applicantAddressZipCode().replace(/(^\d{5}$)|(^\d{5}-\d{4}$)/, ''));
if (dataValue > 9999999999999.99 || dataValue < 0) {
applicantAddressZipCode('');
}
if (loading == false) {
sendCommand('SAVE');
}
}
});
function formatZipCode(value) {
var Z = /(\d{5})(\d+)/;
if (value != undefined && value != '') {
return value = value.replace(Z, '$1' + '-' + '$2');;
}
else {
return value;
}
};
HTML:
<input type="text" maxlength="9" id="applicantAddressZipCode" class="form-control text-font-md" data-bind="css: applicantAddressZipCodeCSS, attr: { title: applicantAddressZipCodeToolTip }, event: {focusout: checkLostFocus.bind($root, $data, 'applicantAddressZipCode')}, value: applicantAddressZipCode">
it allows one charector, but the charector has been counted as a digit which it shouldn’t be. I want to put that charector in the proper place in case has been entered. PLEASE HELP!