Hsl.Formatter
phoneSimple
Hsl.Formatter.phoneSimple(c: Xrm.FormContext | Hsl.FormContext, field: string, opts?: PhoneOptions): void;
Hsl.Formatter.phoneSimple(c: Xrm.FormContext | Hsl.FormContext, fields: string[], opts?: PhoneOptions): void;
Applies a phone formatting algorithm whenever the attribute value changes.
Digits are defined as numbers 0-9
- If the number starts with '+' or another non-digit, no format is applied.
- If the phone number starts with exactly 7 digits, formats the number as 999-9999.
- If it starts with 10 or more digits, formats the number as 999-999-9999 followed by a space followed by any additional digits or text. For example, 987654321012345 would be formatted as 987-654-3210 12345.
- For purposes of measuring the number of starting digits, it is the number of digits before any characters that are not digits, space, hyphen, comma, or a period/dot. For example, 423-343-2344 x1234 has 10 digits before the first non-digit character "x".
- If the number has 0 to 6 or 8 to 9 digits, no format is applied
phoneAggressive
Hsl.Formatter.phoneAggressive(c: Xrm.FormContext | Hsl.FormContext, field: string, opts?: PhoneOptions): void;
Hsl.Formatter.phoneAggressive(c: Xrm.FormContext | Hsl.FormContext, fields: string[], opts?: PhoneOptions): void;
Applies a phone formatting algorithm whenever the attribute value changes.
Digits are defined as letters or numbers a-z, A-Z, 0-9
- If the number starts with '+' or another non-digit, no format is applied.
- If the phone number starts with plus, a 0, an asterisks, or is less than 10 digits, leave it alone.
- Remove everything from the phone number except digits
- If the phone number starts with a 1, remove the 1.
- If the phone number is less than 10 and not exactly 7 digits, leave it alone.
- Format the first 10 (or 7) characters based on selected format
- If there are additional characters after the first 10, add a space and display remaining characters.
Algorithm Comparison
Input | Simple | Aggressive |
---|---|---|
(864) 555-5555 | (864) 555-5555 | (864) 555-5555 |
864-555-5555 | (864) 555-5555 | (864) 555-5555 |
8645555555 | (864) 555-5555 | (864) 555-5555 |
12234567890 | (122) 345-6789 0 | (223) 456-7890 |
777-113-3223 (mobile) | (777) 113-3223 (mobile) | (777) 113-3223 mobile |
999-123-9121 ask for Chris | (999) 123-9121 ask for Chris | (999) 123-9121 askforChris |
800 car4you | 800 car4you | (800) car-4you |
800-8-Novelty | 800-8-Novelty | (800) 8No-velt y |
1800contacts | 1800contacts | (800) con-tact s |
No telephone | No telephone | (Not) ele-phon e |
-30302959 | -30302959 | -30302959 |
492-32092-12 | (492) 320-9212 | (492) 320-9212 |
93ee39213 | 93ee39213 | 93ee39213 |
39&2-842-8942 | 39&2-842-8942 | (392) 842-8942 |
555-4532 | 555-4532 | 555-4532 |
238-3282 a3 | 238-3282 a3 | 238-3282 a3 |
239-2398 x32 | 239-2398 x32 | (239) 239-8x32 |
3290320 | 329-0320 | 329-0320 |
322cars | 322cars | 322-cars |
87654321 | 87654321 | 87654321 |
876543219 | 876543219 | 876543219 |