https://github.com/zhoukekestar/input-validator
Validator for input control.
https://github.com/zhoukekestar/input-validator
ajax form input validation validator
Last synced: 3 months ago
JSON representation
Validator for input control.
- Host: GitHub
- URL: https://github.com/zhoukekestar/input-validator
- Owner: zhoukekestar
- License: mit
- Created: 2017-05-15T11:36:12.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-08-31T07:16:18.000Z (over 8 years ago)
- Last Synced: 2025-01-20T23:48:06.617Z (about 1 year ago)
- Topics: ajax, form, input, validation, validator
- Language: JavaScript
- Size: 32.2 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# input-validator
Lightweight validator for input control.
If you only use `core.js`. You will see different notification on different browser.
| Chrome | Firefox | IE |
| --- | --- | --- |
|  |  |  |
Test this [core feature online](https://zhoukekestar.github.io/input-validator/test/core.html).
# Features
* `setDefaultMessages` to set messages for `patternMismatch`, `valueMissing` and so on. [Try this online.](https://zhoukekestar.github.io/input-validator/test/core-default-messages.html)
```js
HTMLInputValidatorElement.setDefaultMessages({
valueMissing: 'Sorry, you have to input this. by default message~'
})
```
* `registerType` to register your custom type. [Try this online.](https://zhoukekestar.github.io/input-validator/test/core-register-type.html)
```html
HTMLInputValidatorElement.registerType('OneORZero', function (value) {
if (value === '0' || value === '1') return '';
return 'Please input 0 or 1.';
});
```
* `title` Set title to show custom message. [Try this online.](https://zhoukekestar.github.io/input-validator/test/core-title.html)
```html
```
# Events
This is an enhancement feature (not W3C). Because native `invalid` event can't bubbles to parents.
* `input-valid` if an input set a valid value.
* `input-invalid` if an input set a invalid value.
# Submit
This is an enhancement feature (not W3C).
Browser won't check validity if you call native submit by js. We hook the native
submit to check validity. So you can submit form by `input`, `button` or `submit()`.
```html
button
submit()
```
# Browser Compatibility
* `checkValidity` [IE 10+](http://caniuse.com/#search=checkValidity)
# Third Party
* `form-json` This library works well with form-json. [Try this online.](https://zhoukekestar.github.io/input-validator/test/work-with-form-json.html)
```html
```
# Read More
* [constraintvalidation on html5rocks](https://www.html5rocks.com/en/tutorials/forms/constraintvalidation/)
* [Form_validation on MDN](https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Form_validation)