aspnet-client-validation
aspnet-client-validation copied to clipboard
Is it possible to inherit from or access an existing provider
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?
If you make a new MvcValidationProviders() you can access the default implementations.