Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sanv92/form-request-validation
A simple and flexible form validation library that allows you to send any request and validate it against customizable field options. Easily define validation rules, patterns, and error handling for various forms and fields.
https://github.com/sanv92/form-request-validation
Last synced: about 1 month ago
JSON representation
A simple and flexible form validation library that allows you to send any request and validate it against customizable field options. Easily define validation rules, patterns, and error handling for various forms and fields.
- Host: GitHub
- URL: https://github.com/sanv92/form-request-validation
- Owner: sanv92
- Created: 2024-09-05T18:49:11.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-09-05T20:22:31.000Z (5 months ago)
- Last Synced: 2024-12-22T05:30:35.621Z (about 1 month ago)
- Language: TypeScript
- Homepage: https://it4you.dev
- Size: 207 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Form Request Validation
A simple and flexible form validation library that allows you to send any request and validate it against customizable field options. Easily define validation rules, patterns, and error handling for various forms and fields.
## Installation
To install the package, use npm:
```bash
npm install form-request-validation
```or with yarn:
```bash
yarn add form-request-validation
```## Usage
First, you need to configure your AWS credentials to allow the package to send emails using AWS SES. This can be done by setting up environment variables:
```typescript
import { validateEmailRequest, LanguageValidationRules, ValidationRules } from 'form-request-validation'const fieldOptions = {
emailFrom: {
name: 'Email From',
required: true,
validation: true,
minLength: 1,
maxLength: 500,
pattern: /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$/i,
errorMessage: 'Please provide a valid email address',
},
subject: {
name: 'Subject',
required: false,
validation: true,
pattern: createValidationRegex(LanguageValidationRules.LatinAlphabetPattern, LanguageValidationRules.EstonianPattern, ValidationRules.SpecialCharacterPattern),
errorMessage: 'Please provide a valid subject',
},
}const defaultFieldOptions = {
subject: {
name: 'Subject',
required: false,
validation: true,
pattern: createValidationRegex(LanguageValidationRules.LatinAlphabetPattern),
errorMessage: 'Please provide a valid subject',
}
}const formRequest = {
emailFrom: '[email protected]',
subject: 'Contact Us Form Submission',
message: 'This is a test message from the contact form.',
}const validationErrors = validateEmailRequest(formRequest, fieldOptions, defaultFieldOptions)
if (validationErrors.length > 0) {
throw Error(JSON.stringify(validationErrors))
}
```## License
This project is licensed under the MIT License. See the LICENSE file for more details.## Contributing
Contributions are welcome! Please feel free to submit a Pull Request or open an issue on GitHub if you find a bug or have a suggestion for improvement.