PhoneNumberParser¶
Parses a free-form phone-number string into a ComponentizedPhoneNumber (area code/prefix/number), first stripping common punctuation ((, ), -, .) and confirming the remaining digits form a valid 10-digit numeric string before splitting it.
Purpose¶
- Validates whether a given string, once punctuation is stripped, represents a parseable 10-digit US phone number.
- Splits a valid 10-digit phone number into area code, prefix, and subscriber-number components.
Context¶
- Namespace:
SAIF.Services.Utilities - Assembly/package:
SAIF.Services(packaged inside theSAIF.SAIFCode.CoreNuGet package)
Public members¶
| Member | Signature | Purpose |
|---|---|---|
| PhoneNumberParser(...) | public PhoneNumberParser(string phoneNumber) |
Stores the raw phone-number string to be parsed. |
| Parse | public ComponentizedPhoneNumber Parse() |
Returns the phone number split into area code/prefix/number when CanParse() succeeds, otherwise returns null. |
| CanParse | public bool CanParse() |
Returns true when the de-formatted (punctuation-stripped) phone number is exactly 10 numeric characters. |
Behavioral notes¶
- De-formatting strips only
(,),-, and.characters — other non-numeric characters (e.g., spaces or letters) would causeCanParse()to fail thedouble.TryParsecheck.
Sources¶
- Services/SAIF.Services/Utilities/PhoneNumberFormatter.cs