Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export class NumberValidators {
- static integer(maxDigits: number = 22){
- return this.decimal(22, 0);
- }
- static decimal(maxDigits: number = 22, maxDecimals: number = 22){
- return (control: AbstractControl): ValidationErrors | null => {
- let value:string = control.value;
- if(isEmpty(value)) return null;
- let matches = String(value).match(FLOAT_REGEX);
- if(matches === null) return {'float': true};
- if(matches[2] !== undefined) {
- if((matches[1].length + matches[2].length) > maxDigits) return
- {'float': true};
- if(matches[2].length > maxDecimals) return {'float': true};
- } else {
- if((matches[1].length) > maxDigits) return {'float': true};
- }
- return null;
- };
- }
- }
- rowIndexControl = new FormControl('', [NumberValidators.integer()]);
- positionIndexControl = new FormControl('', [NumberValidators.integer()]);
- rowDistanceControl = new FormControl('', [NumberValidators.integer()]);
- colDistanceControl = new FormControl('', [NumberValidators.integer()]);
- Validators.pattern(/^[0-9]+$/)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement