"angular format phone number while typing" Code Answer's
You're definitely familiar with the best coding language Javascript that developers use to develop their projects and they get all their queries like "angular format phone number while typing" answered properly. Developers are finding an appropriate answer about angular format phone number while typing related to the Javascript coding language. By visiting this online portal developers get answers concerning Javascript codes question like angular format phone number while typing. Enter your desired code related query in the search bar and get every piece of information about Javascript code related question on angular format phone number while typing.
angular format phone number while typing
export class PhoneMaskDirective {
constructor(public ngControl: NgControl) { }
@HostListener('ngModelChange', ['$event'])
onModelChange(event) {
this.onInputChange(event, false);
}
@HostListener('keydown.backspace', ['$event'])
keydownBackspace(event) {
this.onInputChange(event.target.value, true);
}
onInputChange(event, backspace) {
let newVal = event.replace(/\D/g, '');
if (backspace && newVal.length <= 6) {
newVal = newVal.substring(0, newVal.length - 1);
}
if (newVal.length === 0) {
newVal = '';
} else if (newVal.length <= 3) {
newVal = newVal.replace(/^(\d{0,3})/, '($1)');
} else if (newVal.length <= 6) {
newVal = newVal.replace(/^(\d{0,3})(\d{0,3})/, '($1) $2');
} else if (newVal.length <= 10) {
newVal = newVal.replace(/^(\d{0,3})(\d{0,3})(\d{0,4})/, '($1) $2-$3');
} else {
newVal = newVal.substring(0, 10);
newVal = newVal.replace(/^(\d{0,3})(\d{0,3})(\d{0,4})/, '($1) $2-$3');
}
this.ngControl.valueAccessor.writeValue(newVal);
}
}
Source: stackoverflow.com
All those coders who are working on the Javascript based application and are stuck on angular format phone number while typing can get a collection of related answers to their query. Programmers need to enter their query on angular format phone number while typing related to Javascript code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about angular format phone number while typing for the programmers working on Javascript code while coding their module. Coders are also allowed to rectify already present answers of angular format phone number while typing while working on the Javascript language code. Developers can add up suggestions if they deem fit any other answer relating to "angular format phone number while typing". Visit this developer's friendly online web community, CodeProZone, and get your queries like angular format phone number while typing resolved professionally and stay updated to the latest Javascript updates.