Page 1 of 1
Phone number format
Posted: Wed Sep 23, 2020 1:41 am
by JohnR
How can I edit a phone number so that the dashes appear when submitted in a form?
Re: Phone number format
Posted: Wed Sep 23, 2020 2:09 am
by BaconFries
It can done using regex see the following for Telephone Number Validation
Telephone Number Validation
Similar Question
Similar
Re: Phone number format
Posted: Wed Sep 23, 2020 2:27 am
by JohnR
Where do you place the expression, e.g. /^(\()?\d{3}(\))?(-|\s)?\d{3}(-|\s)\d{4}$/
Re: Phone number format
Posted: Wed Sep 23, 2020 2:38 am
by BaconFries
In the Editbox properties you can set the validation data type to 'custom'
Re: Phone number format
Posted: Wed Sep 23, 2020 10:21 pm
by JohnR
I set the Data Type to 'Custom' and placed /^(\()?\d{3}(\))?(-|\s)?\d{3}(-|\s)\d{4}$/
in the Custom Expression box but it doesn't make any difference.
Re: Phone number format
Posted: Thu Sep 24, 2020 6:25 am
by Pablo
How can I edit a phone number so that the dashes appear when submitted in a form?
There is no standard solution for this in HTML, this require a custom script.
Re: Phone number format
Posted: Thu Sep 24, 2020 4:27 pm
by BaconFries
Re: Phone number format
Posted: Mon Sep 28, 2020 6:55 pm
by JohnR
I checked the above link and ran the snippet. Now the question:
where do I place
Var Phone...
$('#phone'...
and
<script src...
Re: Phone number format
Posted: Tue Sep 29, 2020 1:36 pm
by BaconFries
Place the following between the <head></head> in Page HTML then change the ID of the input "Editbox" to phone
Code: Select all
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script>
$('#phone').focusout(function() {
function phoneFormat() {
phone = phone.replace(/[^0-9]/g, '');
phone = phone.replace(/(\d{3})(\d{3})(\d{4})/, "($1) $2-$3");
return phone;
}
var phone = $(this).val();
phone = phoneFormat(phone);
$(this).val(phone);
});
</script>
Re: Phone number format
Posted: Wed Dec 16, 2020 4:41 pm
by JohnR
I tried this with the PAGE HTML and it doesn't seem to work.
Could it be because the phone number is in a FORM?