| 4 |
lars |
1 |
[jQuery Validation Plugin](https://jqueryvalidation.org/) - Form validation made easy
|
|
|
2 |
================================
|
|
|
3 |
|
|
|
4 |
[](https://github.com/jquery-validation/jquery-validation/releases/latest)
|
|
|
5 |
[](https://travis-ci.org/jquery-validation/jquery-validation)
|
|
|
6 |
[](https://david-dm.org/jquery-validation/jquery-validation#info=devDependencies)
|
|
|
7 |
[](https://www.jsdelivr.com/package/npm/jquery-validation)
|
|
|
8 |
|
|
|
9 |
The jQuery Validation Plugin provides drop-in validation for your existing forms, while making all kinds of customizations to fit your application really easy.
|
|
|
10 |
|
|
|
11 |
## Getting Started
|
|
|
12 |
|
|
|
13 |
### Downloading the prebuilt files
|
|
|
14 |
|
|
|
15 |
Prebuilt files can be downloaded from https://jqueryvalidation.org/
|
|
|
16 |
|
|
|
17 |
### Downloading the latest changes
|
|
|
18 |
|
|
|
19 |
The unreleased development files can be obtained by:
|
|
|
20 |
|
|
|
21 |
1. [Downloading](https://github.com/jquery-validation/jquery-validation/archive/master.zip) or Forking this repository
|
|
|
22 |
2. [Setup the build](CONTRIBUTING.md#build-setup)
|
|
|
23 |
3. Run `grunt` to create the built files in the "dist" directory
|
|
|
24 |
|
|
|
25 |
### Including it on your page
|
|
|
26 |
|
|
|
27 |
Include jQuery and the plugin on a page. Then select a form to validate and call the `validate` method.
|
|
|
28 |
|
|
|
29 |
```html
|
|
|
30 |
<form>
|
|
|
31 |
<input required>
|
|
|
32 |
</form>
|
|
|
33 |
<script src="jquery.js"></script>
|
|
|
34 |
<script src="jquery.validate.js"></script>
|
|
|
35 |
<script>
|
|
|
36 |
$("form").validate();
|
|
|
37 |
</script>
|
|
|
38 |
```
|
|
|
39 |
|
|
|
40 |
Alternatively include jQuery and the plugin via requirejs in your module.
|
|
|
41 |
|
|
|
42 |
```js
|
|
|
43 |
define(["jquery", "jquery.validate"], function( $ ) {
|
|
|
44 |
$("form").validate();
|
|
|
45 |
});
|
|
|
46 |
```
|
|
|
47 |
|
|
|
48 |
For more information on how to setup a rules and customizations, [check the documentation](https://jqueryvalidation.org/documentation/).
|
|
|
49 |
|
|
|
50 |
## Reporting issues and contributing code
|
|
|
51 |
|
|
|
52 |
See the [Contributing Guidelines](CONTRIBUTING.md) for details.
|
|
|
53 |
|
|
|
54 |
**IMPORTANT NOTE ABOUT EMAIL VALIDATION**. As of version 1.12.0 this plugin is using the same regular expression that the [HTML5 specification suggests for browsers to use](https://html.spec.whatwg.org/multipage/forms.html#valid-e-mail-address). We will follow their lead and use the same check. If you think the specification is wrong, please report the issue to them. If you have different requirements, consider [using a custom method](https://jqueryvalidation.org/jQuery.validator.addMethod/).
|
|
|
55 |
In case you need to adjust the built-in validation regular expression patterns, please [follow the documentation](https://jqueryvalidation.org/jQuery.validator.methods/).
|
|
|
56 |
|
|
|
57 |
**IMPORTANT NOTE ABOUT REQUIRED METHOD**. As of version 1.14.0 this plugin stops trimming white spaces from the value of the attached element. If you want to achieve the same result, you can use the [`normalizer`](https://jqueryvalidation.org/normalizer/) that can be used to transform the value of an element before validation. This feature was available since `v1.15.0`. In other words, you can do something like this:
|
|
|
58 |
``` js
|
|
|
59 |
$("#myForm").validate({
|
|
|
60 |
rules: {
|
|
|
61 |
username: {
|
|
|
62 |
required: true,
|
|
|
63 |
// Using the normalizer to trim the value of the element
|
|
|
64 |
// before validating it.
|
|
|
65 |
//
|
|
|
66 |
// The value of `this` inside the `normalizer` is the corresponding
|
|
|
67 |
// DOMElement. In this example, `this` references the `username` element.
|
|
|
68 |
normalizer: function(value) {
|
|
|
69 |
return $.trim(value);
|
|
|
70 |
}
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
});
|
|
|
74 |
```
|
|
|
75 |
|
|
|
76 |
## License
|
|
|
77 |
Copyright © Jörn Zaefferer<br>
|
|
|
78 |
Licensed under the MIT license.
|