MCPcopy Create free account
hub / github.com/NativeScript/NativeScript / formatPhoneNumber

Function formatPhoneNumber

apps/toolbox/src/pages/forms.ts:39–61  ·  view source on GitHub ↗
(value: string, useParens?: boolean)

Source from the content-addressed store, hash-verified

37}
38
39function formatPhoneNumber(value: string, useParens?: boolean) {
40 value = value.replace(/\D/g, '');
41 var size = value.length;
42 if (useParens) {
43 if (size > 0) {
44 value = '(' + value;
45 }
46 if (size > 3) {
47 value = value.slice(0, 4) + ') ' + value.slice(4, 11);
48 }
49 if (size > 6) {
50 value = value.slice(0, 9) + '-' + value.slice(9);
51 }
52 } else {
53 if (size > 3) {
54 value = value.slice(0, 3) + '-' + value.slice(3, 10);
55 }
56 if (size > 6) {
57 value = value.slice(0, 7) + '-' + value.slice(7);
58 }
59 }
60 return value;
61}
62
63function formatSSN(value: string) {
64 // if input value is falsy eg if the user deletes the input, then just return

Callers

nothing calls this directly

Calls 2

replaceMethod · 0.80
sliceMethod · 0.45

Tested by

no test coverage detected