1.1.6 • Published 9 months ago
validator-package v1.1.6
Validator Package
Validator Package
is an Angular package that provides various form validation functions for use in Angular reactive forms. These validators help enforce specific rules for input fields to enhance user experience and data integrity.
Functions
1. allowedOnlyKeyboardNumbers
- Description: Purpose: Restricts input to only numeric characters (0-9) and certain control keys. Prevents non-numeric characters from being entered via the keyboard.
2. isValidEmail
- Description: Validates if the provided email address follows a proper email format.
3. alphaNumbersSpaceValidator
- Description: Ensures that the input starts with an alphanumeric character and does not contain leading or double spaces. Accepts alphanumeric characters and spaces.
4. alphaNumbersExceptSpaceValidator
- Description: Validates that the input starts with an alphanumeric character and does not contain any spaces.
5. alphaNumbersExceptDoubleSpaceValidator
- Description: Checks that the input does not start with a space and does not contain double spaces.
6. alphaSpaceValidator
- Description: Validates that the input contains only alphabetic characters and spaces, without leading spaces or double spaces.
7. alphaNumbersValidator
- Description: Ensures the input consists of only alphanumeric characters, without leading spaces or double spaces.
8. urlValidator
- Description: Validates that the input is a properly formatted URL.
9. alphaValidator
- Description: Validates that the input consists of only alphabetic characters.
10. noSpaceValidator
- Description: Checks that the input does not contain any spaces.
11. previousDateValidator
- Description: Validates that the date entered is not a future date.
12. currentDateValidator
- Description: Validates that the date entered is not in the future compared to the current date.
13. defalutDateValidator
- Description: Validates the format of the date input.
14. futureDateFromCurrentValidator
- Description: Validates that the date entered is not in the past compared to the current date.
15. futureDateValidator
- Description: Validates that the date entered is at least one day in the future.
16. checkFormat(selectDate: any): any
- Description: Checks if the date input is a valid date format.
17. dateAllowedOnlyNumbers
- Description: Restricts date input to numeric characters and certain control keys.
18. allowedOnlyRoundedNumbersValidator
- Description: Validates that the input is a rounded number (integer).
19. allowedNumberWithDecimal
- Description: Validates that the input is a number that may contain decimals.
20. allowedNumberDecimalWithNegative
- Description: Validates that the input is a decimal number which may also be negative.
21. allowedOnlyNUmbersValidator
- Description: Validates that the input consists of only numeric characters.
22. allowedOnlyCurrencyValidator
- Description: Validates that the input consists of valid currency characters.
23. allowedOnlyPositiveNUmbersValidator
- Description: Validates that the input consists of only positive numeric characters.
24. twoDatesValidator(second: any): ValidatorFn
- Description: Validates that the first date is not after the second date.
25. twoDatesExpValidator(second: any): ValidatorFn
- Description: Validates that the first date is not after the second date, with additional checks.
26. ssnValidator(min: number): ValidatorFn
- Description: Validates the length of a Social Security Number (SSN) input.
27. numbersWithLengthValidator(min: number): ValidatorFn
- Description: Validates that the input is numeric and meets a minimum length requirement.
28. getDate(selectDate: any): any
- Description: Checks if a given date is greater than the current date.
29. isTouchedDirty(groupName: any, fieldName: string): boolean
- Description: Checks if a specific form field is invalid and has been interacted with (touched or dirty).
Usage
To use the validators from the validator-package
, import the necessary functions directly into your Angular component. You can then apply the validators to your form controls as needed.
Example Component Code
import { Component } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { isValidEmail, allowedOnlyKeyboardNumbers } from 'validator-package';
@Component({
selector: 'app-my-form',
templateUrl: './my-form.component.html'
})
export class MyFormComponent {
myForm: FormGroup;
constructor(private fb: FormBuilder) {
this.myForm = this.fb.group({
email: ['', [Validators.required, isValidEmail]],
numberField: ['', allowedOnlyKeyboardNumbers]
});
}
onSubmit() {
if (this.myForm.valid) {
console.log(this.myForm.value);
}
}
}