I am having trouble with a decimal regex that needs to allow positive or negative numbers and up to 8 decimals.
Here is what I have.
^-?(?:(?:0|[1-9][0-9]*)(?:\.[0-9]{1,9})?|\.[0-9]{1,9})$ For the most part, this works, but it does not validate .00000001 and I cannot figure out why. It doesnt seem to work for any decimal where I have more than 6 zeros i a row.
export class AmountValidateDirective implements Validator { validate(c: FormControl): any { let amount = c.value; const isValid = /^-?(?:(?:0|[1-9][0-9]*)(?:\.[0-9]{1,9})?|\.[0-9]{1,9})$/.test(amount); const message = { 'amountValidate': { 'message': 'Must be Decimal with less than 8 digits' } }; return isValid ? null : message; } }
^[+-]?\d*\.\d{1,8}$?