An 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.
npm i @marcellodotgg/ngx-validators
- You can read the documentation here: DOCUMENTATION
- You can view the demo form here: DEMO
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.any("endDate")),
endDate: new FormControl("", Validators.any("startDate")),
});
}
if(condition: boolean)
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
streetAddress
unless(condition: boolean)
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
out
base64
creditCard
number
NaN
url
Pull Requests are welcome. We require passing tests and descriptions should be filled out. In addition, update any documentation if needed.
PRs may be closed for any reason.