In my Angular component, I have a phone number field.
For example, +36 42534534534
I am trying to extract the code before the space and the phone number after the space.
This is how I am currently handling it:
set phoneNumberResult(value: string) {
if (this.phoneNumberResult !== value) {
this.phoneCode = value.substr(0, 3);
this.phoneNumber = value.substr(5, value.length - 5);
this.changed.forEach(f => f(value));
}
}
However, the phone code can vary in length (3, 4, or 5 symbols), so I need to get all characters before the space as well as those after the space to determine both the phoneCode
and phoneNumber
.
What would be the correct approach to achieve this?