Reputation: 31
I need a regular expression for accepting eight digits and after that one dot and after that only two digits for amount fields.
Currently I'm using this much of code...
valLowLTL(val) {
const val1 = val.split('.');
const amountLowLTL = this.addBillingForm.get('invoicingAmtLowLTL') as FormControl;
const re = /,/gi;
val1[0] = val1[0].replace(re, '');
if (val1[0].length > 8) {
val1[0] = val1[0].substring(0, 8);
}
amountLowLTL.setValue(val1[0]);
if (val1.length > 1) {
if (val1[1].length > 2) {
val1[1] = val1[1].substring(0, 2);
}
const lowValLTL = val1[0].concat('.').concat(val1[1]);
amountLowLTL.setValue(lowValLTL);
}
}
I just need an simple regular expression which helps me out.
Upvotes: 2
Views: 365
Reputation: 5472
[\d]{8}\.[\d]{2}
or
[0-9]{8}\.[0-9]{2}
https://regex101.com/r/SBAUc8/1
Upvotes: 1