3.0.0 • Published 3 years ago
@terminus/ui-validators v3.0.0
A collection of form validators.
Table of Contents
NOTE: This service is provided as a singleton by defining the providedIn
property as root
.
Usage
import {
FormBuilder,
FormGroup,
} from '@angular/forms';
import { TsValidatorsService } from '@terminus/ui-validators';
@Component({
...
})
export class MyComponent {
// Create a form
myForm: FormGroup = this.formBuilder.group({
email: [
null,
[
// Basic validator
this.validatorsService.email(),
],
],
greaterThan: [
null,
[
// Validator with a required argument
this.validatorsService.greaterThan(10),
],
],
});
constructor(
private formBuilder: FormBuilder,
private validatorsService: TsValidatorsService,
) {}
}
Available validators
Validator | Purpose |
---|---|
creditCard | A credit card number must be valid |
email | An email address must be valid |
domain | A domain must be valid |
equalToControl | A control's value must be equal to another control's value |
greaterThan | A number must be greater than another value |
inCollection | A value must be found in a collection |
isInRange | A number must be between two numbers |
lessThan | A number must be less than another value |
lowercase | A value must contain a minimum amount of lowercase characters |
maxDate | A date must be before a maximum date |
minDate | A date must be after a minimum date |
numbers | A value must contain a minimum amount of numbers |
password | A password must meet certain requirements |
uppercase | A value must contain a minimum amount of uppercase characters |
url | A URL must be valid |
Mocking
A mocked version of the service is available for testing as TsValidatorsServiceMock
from @terminus/ui-validators/testing
.
The mocks consist of Jest mock functions. Based on the class value isValid
the validator mock will
return an error message or null
.
3.0.0
3 years ago
2.0.5
3 years ago
2.0.4
4 years ago
2.0.3
4 years ago
2.0.2
4 years ago
2.0.1
4 years ago
2.0.0
4 years ago
1.1.0
4 years ago
1.0.13
4 years ago
1.0.12
4 years ago
1.0.11
4 years ago
1.0.10
4 years ago
1.0.9
4 years ago
1.0.8
4 years ago
1.0.7
4 years ago
1.0.6
4 years ago
1.0.5
4 years ago
1.0.4
4 years ago
1.0.2
4 years ago
1.0.3
4 years ago
1.0.1
4 years ago
1.0.0
4 years ago
0.0.2
4 years ago
0.0.1
4 years ago