GVDefaultValidators
GVDefaultValidators
is a utility class that provides a set of static methods to create custom validators used in conjunction with the @GV
decorator for model validation. Each static method returns a ValidatorFn
, which is a function that validates form control values based on specific rules. These validators can be applied to properties of a model class to enforce various validation constraints, such as required fields, specific patterns, minimum and maximum lengths, numeric values, email format, and more.
required(): ValidatorFn
Description: Creates a validator function that checks whether a form control has a non-null and non-undefined value, ensuring that the control is required.
Usage:
import { GV } from '@releasium/ngx-grand-validator';
class UserModel {
@GV.required()
firstName: string;
}
pattern(pattern: RegExp): ValidatorFn
Description: Creates a validator function that checks whether a form control value matches the provided regular expression pattern.
Parameters:
pattern
(RegExp): The regular expression pattern to be matched.Usage:
import { GV } from '@releasium/ngx-grand-validator';
class UserModel {
@GV.pattern(/^[A-Za-z]+$/)
username: string;
}
digit(): ValidatorFn
Description: Creates a validator function that checks whether a form control value contains only digits.