A series of Angular Form Validators to help speed up common validation scenarios by extending the ones provided by the Angular team.
npm install @marcellodotgg/ngx-validatorsAn extension of the Validators provided by the @angular team. Angular provides great out-of-the-box Validators for forms. However, they don't have validators when you need to depend on other FormControls. We extend the Validators provided by Angular and give more useful ones, particularly with cross-control functionality.
While this is on NPM and available to install as a dependency, I encourage you to copy the file and move into your code base to avoid a dependency.
sh
npm i @marcellodotgg/ngx-validators
`Documentation and Demo
* You can read the documentation here: DOCUMENTATION
* You can view the demo form here: DEMO Sample Usage
`ts
import { Validators } from "@marcellodotgg/ngx-validators";class MyComponent {
// first name is always required
// start and end date is optional, unless you enter a start date or end date.
form = new FormGroup({
firstName: new FormControl("", Validators.required),
startDate: new FormControl("", Validators.requiredIfAny("endDate")),
endDate: new FormControl("", Validators.requiredIfAny("startDate")),
});
}
`API
* if(condition: string)
* any(...controlNames: string[])
* all(...controlNames: string[])
* anyEqual(...controlPairs: [controlName, value][])
* allEqual(...controlPairs: [controlName, value][])
* equal(value: any)
* range(start: number, end: number)
* zipCode
* stateCode
* stateName
* streetAddressFuture Work
* profanity
* lt(controlName: string, opts = { includeFalsy: false })
* lte(controlName: string, opts = { includeFalsy: false })
* gt(controlName: string, opts = { includeFalsy: false })
* gte(controlName: string, opts = { includeFalsy: false })
* json
* in
* notIn
* base64
* creditCard
* number
* NaN
* url`PRs may be closed for any reason.