# Epom-validators
Collection of functions and mini classes that implements validation functionality of FormGroups and FormControls.

| Validator | Description |
|-----------|-------------|
| **EqualsValidators** ||
| **eq**(value: string) | validate equality of `FormControl.value` and `value` |
| **FormValidators** ||
| **compareDates**(form: FormGroup, timeStamp: 'x' \| 'X') | compare dates between each other. Comparing by fields `startDate` & `endDate` |
| **PasswordValidation.matchPassword**(passwordLength: number) | add to FormGroup with controls `password` and `passwordConfirm`, it will match equality between this controls and wathcing that password langth is greater then `passwordLength` |
| **NumberValidators** ||
| **greaterThen**(value: number) | validates that formControl value is number and it greater then `value` |
| **greaterThenOrNUll**(value:number) | validates that formControl value is number or null and it greater then `value` |
| **greaterThenField**(controlTarget: AbstractControl) | validates that formControl value is number and it greater then `controlTarget` value |
| **greaterThenFieldOrNull**(controlTarget: AbstractControl) | validates that formControl value is number or null and it greater then `controlTarget` value |
| **greaterOrEqualThenFieldOrNull**(controlTarget: AbstractControl) | validates that formControl value is number or null and it greater or equal `controlTarget` value |
| **mustBeNumber**() | validates that FormControl value is number |

### Installation
Install `epom-ng2-validators` via npm:
```sh
$ npm install --save epom-ng2-validators
```
That's all, use it.

### Usage

Import needed validators in your files and use;

```typescript
import {EqualsValidators} from 'epom-ng2-validators';
...
new FormControl('', [EqualsValidators.eq(6)]);
```
You can use constants - they contains some validators


| Constant                  | description                                                                                           |
|---------------------------|-------------------------------------------------------------------------------------------------------|
| `FLOAT_REGEXP`            | regex for float numbers                                                                               |
| `NUMBER_REGEXP`           | regex for strict numbers                                                                              |
| `NOT_CIRYLLIC_REGEX`      | anything but not cyrillic symbols                                                                     |
| `NOT_SPECIAL_CHARS_REGEX` | regex for names with cyrillic symbols                                                                 |
| `EMAIL_REGEXP`            | regex for email                                                                                       |
| `PHONE_REGEXP`            | regex for phone                                                                                       |
| `MAX_NAME_SYMBOLS`        | max symbols in name fields (150)                                                                      |
| `MAX_FLOAT_SYMBOLS`       | max symbols in fields with float values                                                               |
| `floatValidators`         | array of validators for float values (float pattern validator and maxLength validator for float)      |
| `namesValidators`         | array of validators for name values (non cyrillic pattern validator and maxLength validator for name) |
| `namesCiryllicValidators` | array of validators for name values (cyrillic pattern validator and maxLength validator for name)     |

## Parts
    .
    |-- epom-ng2-validators
    |   |-- equal.validator
    |   |-- form.validator
    |   |-- number.validator

Examples:
```javascript
new FormGroup().group({
    mustBeNumber: ['', NumberValidators.mustBeNUmber()]
});
```

## Contributors

Gennady Strelets <g.strelets@itmgmedia.net>
