https://github.com/aalfiann/native-form-validation
Native JavaScript Form Validation
https://github.com/aalfiann/native-form-validation
form-validation javascript-validation simple-validation
Last synced: 5 months ago
JSON representation
Native JavaScript Form Validation
- Host: GitHub
- URL: https://github.com/aalfiann/native-form-validation
- Owner: aalfiann
- License: mit
- Created: 2019-10-27T19:26:00.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2025-02-19T20:23:52.000Z (11 months ago)
- Last Synced: 2025-05-07T15:05:46.631Z (9 months ago)
- Topics: form-validation, javascript-validation, simple-validation
- Language: JavaScript
- Homepage:
- Size: 839 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Native Form Validation
[](https://nodei.co/npm/native-form-validation/)
[](https://www.npmjs.org/package/native-form-validation)
[](https://dl.circleci.com/status-badge/redirect/gh/aalfiann/native-form-validation/tree/master)
[](https://snyk.io//test/github/aalfiann/native-form-validation?targetFile=package.json)



[](https://www.jsdelivr.com/package/npm/native-form-validation)
Native JavaScript Form Validation for Browser / UI Framework.
### Background
There is a lot of `Form Validation`, but most of them was created for `jQuery` and too bloated. This is an `native` javascript form validation which is can be use for all kind of javascript UI framework.
### Install using NPM
```bash
$ npm install native-form-validation
// load using require in nodejs
const FormValidation = require('native-form-validation');
// or load using import in typescript
import FormValidation from 'native-form-validation';
// or load use with path for client side
```
**Or simply use with CDN**
```html
```
### Usage
```javascript
var FV = new FormValidation();
// Create the rules
FV.rules({
username: {
required: true,
message: 'Username must be min 3-20 chars!',
minLength:3,
maxLength:20,
regex: /^[a-zA-Z0-9]/,
errorPlace:'username-error',
errorAddClass: {
username_group:'has-danger',
username:'is-invalid'
}
},
email: {
regex: /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
errorPlace:'email-error',
errorAddClass: {
email_group:'has-danger',
email:'is-invalid'
}
}
});
// Validate all
FV.validate();
// Determine is Valid all
if(FV.isValid()) {
// run your code
}
// Validate per element
FV.element('username').validate();
// Determine is Valid per element
if(FV.element('username').isValid()) {
// run your code
}
```
### Documentation
Please see our Wiki at [here](https://github.com/aalfiann/native-form-validation/wiki).