import { AbstractControl, ValidationErrors } from '@angular/forms';

export function aadharValidator(control: AbstractControl): ValidationErrors | null {
    const aadharNumber = control.value;
    const aadharRegex = /^\d{12}$/;  // Aadhar number must be exactly 12 digits

    if (aadharNumber?.length && !aadharRegex.test(aadharNumber)) {
        return { invalidAadhar: true };
    }

    return null;
}


export function accountNumberValidator(control: AbstractControl): ValidationErrors | null {
    const accountNumber = control.value;
    const accountNumberRegex = /^[0-9]{10,17}$/;
    if (accountNumber?.length && !accountNumberRegex.test(accountNumber)) {
        return { invalidAccountNumber: true };
    }
    return null;
}

export function ifscValidator(control: AbstractControl): ValidationErrors | null {
    const ifsc = control.value;
    const ifscRegex = /^[A-Z]{4}0[A-Z0-9]{6}$/;
    if (ifsc?.length && !ifscRegex.test(ifsc)) {
        return { invalidIfsc: true };
    }
    return null;
}

