You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+27-15Lines changed: 27 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,9 @@
1
-
The goal of this project is to create a feature rich jQuery plugin used for validating form data and that
2
-
keeps the HTML code clean from javascript logic. Even though the plugin has **a wide range of validation functions**
3
-
it's going to be suitable for **mobile websites**. This is achieved by grouping together functions in "modules", making
4
-
it possible for the programmer to load **only those function that's needed** to validate a particular form.
5
-
6
1
2
+
The goal of this project is to create a feature rich jQuery plugin used for validating form data and that
3
+
keeps the HTML code clean from javascript logic. Even though the plugin has **a wide range of validation functions**
4
+
it's designed to consume the least amount bandwidth as possible (which makes it very suitable for **mobile websites**).
5
+
This is achieved by grouping together functions in "modules", making it possible for the programmer
6
+
to load **only those functions that's needed** to validate a particular form.
7
7
8
8
*Usage example*
9
9
@@ -37,7 +37,7 @@ it possible for the programmer to load **only those function that's needed** to
37
37
```
38
38
39
39
## Features
40
-
### Default validators
40
+
### Default validators (no module needed)
41
41
***validate_url**
42
42
***validate_email**
43
43
***validate_domain** — *domain.com*
@@ -62,18 +62,24 @@ it possible for the programmer to load **only those function that's needed** to
62
62
### Module: sweden
63
63
***validate_swemob** — *validate that the value is a swedish mobile telephone number*
64
64
***validate_swesec** — *validate swedish social security number*
65
+
***validate_county** - *validate that the value is an existing county in Sweden*
66
+
***validate_municipality** - *validate that the value is an existing municipality in Sweden*
65
67
66
68
### Module: ukvat
67
69
***validate_ukvatnumber**
68
70
69
71
### Misc (part of core)
70
72
* Show help information automatically when input is focused
71
73
* Validate given values immediately when input is blurred.
74
+
* Make validation optional by adding attribute data-validation-optional="true" to the element. This means
75
+
that the validation defined in data-validation only will take place in case a value is given.
76
+
* Make validation dependent on another input of type checkbox being checked by adding attribute
77
+
data-validation-if-checked="name of checkbox input"
72
78
73
79
74
80
## Writing a custom validator
75
81
You can use the function `$.formUtils.addValidator()` to add your own validation function. Here's an example of a validator
76
-
that checks if the input contains an even number
82
+
that checks if the input contains an even number.
77
83
78
84
```html
79
85
<html>
@@ -103,11 +109,12 @@ that checks if the input contains an even number
103
109
104
110
*name* - The name of the validator, which is used in the validation attribute of the input element.
105
111
106
-
*validate* - callback function that validates the input.
112
+
*validate* - Callback function that validates the input. Should return a boolean telling if the value is considered valid or not.
107
113
108
-
*errorMessageKey* - Name of language property that is used in case the value of the input is invalid
114
+
*errorMessageKey* - Name of language property that is used in case the value of the input is invalid.
109
115
110
-
*errorMessage* - An alternative error message that is used if errorMessageKey is left with an empty value
116
+
*errorMessage* - An alternative error message that is used if errorMessageKey is left with an empty value or isn't defined
117
+
in the language object. Note that you also can use [inline error messages](#localization) in your form.
111
118
112
119
113
120
The validation function takes these five arguments:
@@ -141,7 +148,7 @@ It is now possible to show that the value of an input is incorrect immediately w
141
148
```
142
149
143
150
## Show help information
144
-
Since version 1.1 it is possible to display help information for each input. The information will fade in when input is focused and fade out when input is blurred.
151
+
It is possible to display help information for each input. The information will fade in when input is focused and fade out when input is blurred.
0 commit comments