html
<p>
<input type="text" maxlength="40" (input)="recipientReference = deleteSpacing(recipientReference)" [(ngModel)]="recipientReference" style="width: 30vw; padding: 5px;border: 1px solid;border-radius: 5px" />
</p>
ts
deleteSpacing(object){
if(object == this.recipientReference){
if(object.replace(/\s/g, "").length > 11){
let phone = this.recipientReference.substring(0, 2);
if (phone == "+6") {
return object.replace(/\s/g, "").substring(2, 13);
}
return object.replace(/\s/g, "").substring(0, 11);
}
else {
return object.replace(/\s/g, "");
}
} else {
return object.replace(/\s/g, "");
}
return object;
}
return object.replace(/\s/g, "").substring(0, 11); willn't return substring but return whole string. Therefor, return object.replace(/\s/g, "").substring(0, 10); will return substring.
How can i get the substring with 11 characters?