aspnet-client-validation icon indicating copy to clipboard operation
aspnet-client-validation copied to clipboard

Is it possible to inherit from or access an existing provider

Open RyanONeill1970 opened this issue 9 months ago • 1 comments

I have a validation provider that checks for an email address but allows for spaces at the start and end due to copy / paste errors and password managers adding spaces.

public validate(value: string, element: HTMLInputElement, params: any): boolean {
    // Trim the value first, but handle the case where it is null.
    if (value) {
        value = value.trim();
    }
    else {
        // The default validator below allows whitespace through, so we need to handle this case.
        return false;
    }

    // Use the base email validation now we have a trimmed value.
    return window.validationService.providers["email"](value, element, params);
}

It works great in JavaScript or untyped Typescript but when I import the proper definitions from NPM I get errors as I can't access the providers array.

I can work around this, but is there an approved way to access a named provider or to inherit from one?

RyanONeill1970 avatar Feb 26 '25 18:02 RyanONeill1970

If you make a new MvcValidationProviders() you can access the default implementations.

dahlbyk avatar Mar 04 '25 19:03 dahlbyk