Is there a way to format a phone number or social security number in nuBuilder? If not, is there a consideration to add such functionality in the future?
Thanks.
Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
Formatting other numbers
-
- Posts: 785
- Joined: Sun Oct 14, 2018 11:25 am
Re: Formatting other numbers
I use onblur (custom code) to format/convert a phone number into international format.
The onblur event occurs when an object loses focus. A JavaScript function then formats the field's value and
writes the new value back to the field.
The onblur event occurs when an object loses focus. A JavaScript function then formats the field's value and
writes the new value back to the field.
Re: Formatting other numbers
TonyD,
Sorry but there won't be any new functions added to nuBuilder Forte for doing this, but as toms mentioned, you can do it yourself with Javascript.
Steven
Sorry but there won't be any new functions added to nuBuilder Forte for doing this, but as toms mentioned, you can do it yourself with Javascript.
Steven
Re: Formatting other numbers
TonyD,
This is something we did in nuBuilder 3 that might help...
BTW I copied and modified this ( I don't understand regex).
Steven
This is something we did in nuBuilder 3 that might help...
Code: Select all
function nuFormatMobile(t){
if(t.value.length != 10){
alert('Must have 10 numbers');
t.value = '';
return;
}
t.value = t.value.replace(/(\d{4})(\d{3})(\d{3})/, '$1 $2 $3');
t.value = String(t.value).substr(0,12);
}
BTW I copied and modified this ( I don't understand regex).
Steven
-
- Posts: 68
- Joined: Sun Mar 04, 2018 6:38 pm
Re: Formatting other numbers
Here is what I came up with
and then I use it with a simple call in the JavaScript onblur event
I tried to make it expandable to other format ideas as well.
Thanks for the help and suggestions.
Code: Select all
function nuFormatString(s, f, l){
//which format?
switch (f) {
case "SSN":
case "ssn":
// check to see if the number is already formatted correctly
if (s.search(/\d{3}-\d{2}-\d{4}/) === -1) {
//normalize string and remove all unnecessary characters
s = s.replace(/[^\d]/g, "");
//check if number length is OK
if (s.length == l) {
//reformat and return phone number
return s.replace(/(\d{3})(\d{2})(\d{4})/, "$1-$2-$3");
}
}
break;
case "Phone":
case "phone":
// check to see if the number is already formatted correctly
if (s.search(/\(\d{3}\)\s\d{3}-\d{4}/) === -1) {
//normalize string and remove all unnecessary characters
s = s.replace(/[^\d]/g, "");
//check if number length is OK
if (s.length == l) {
//reformat and return phone number
return s.replace(/(\d{3})(\d{3})(\d{4})/, "($1) $2-$3");
}
}
default:
}
return false;
}
Code: Select all
var phone = nuFormatString($(this)[0].value,"Phone",10);
if (phone !== false) {
$(this)[0].value = phone;
$(this).change();
}
Thanks for the help and suggestions.
TonyD