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
$(document).on('blur', '[data-validator]', function () {
29
29
newValidator($(this));
@@ -75,3 +75,100 @@ you can specify some rules as warning errors, this completable with bootstrap 3
75
75
</form>
76
76
```
77
77
78
+
### Available Validation Rules
79
+
80
+
| Rule | example | description |
81
+
| ------------- | :------:|------|
82
+
| required |`required`| The field under validation must be present in the input data and not empty |
83
+
| numeric |`numeric`| The field under validation must be numeric |
84
+
| integer |`integer`| The field under validation must be an integer |
85
+
| between_numeric |`between_numeric:10,40`| The numeric field under validation must be between the given two values |
86
+
| max_numeric |`max_numeric:60`| The numeric field under validation must less than or equal the given value |
87
+
| min_numeric |`min_numeric:10`| The numeric field under validation must greater than or equal the given value |
88
+
| size_numeric |`size_numeric:10`| The numeric field under validation must exactly equal the given value |
89
+
| between |`between:2,10`| The field length must between the two given values |
90
+
| max |`max:10`| The field length must less than or equal the given value |
91
+
| min |`min:2`| The field length must greater than or equal the given value |
92
+
| size |`size:6`| The field length must exactly equal the given value |
93
+
| date |`date`| The field must be valid date syntax (`new Date()`) |
94
+
| before |`before:2015-01-01`| The date value must be older than the given value |
95
+
| before_or_equal |`before_or_equal:2018-12-01 14:00:00`| The date value must be older than or equal the given value |
96
+
| after |`after:2015-01-01`| The date value must be newer than the given value |
97
+
| after_or_equal |`after_or_equal:2018-12-01 14:00:00`| The date value must be newer than or equal the given value |
98
+
| email |`email`| The field under validation must be formatted as an e-mail address |
99
+
| in |`in:male,female,...`| The field under validation must be included in the given list of values |
100
+
| not_in |`not_in:foo,bar,...`| The field under validation must not be included any of the given list of values |
101
+
| regex |`regex:[A-Z0-9]{6}`| The field under validation must match the given regular expression |
102
+
| different |`different:old_password`| The field under validation must have a different value than field with the given field `name` (attribute) |
103
+
| same |`same:password`| The field under validation must exactly the same value of the field with the given field `name` (attribute) |
104
+
| required_if |`required_if:old_password`| The field under validation must have a value if the field with the given `name` (attribute) is entered |
105
+
| required_if_val |`required_if_val:password,123456`| The field under validation must have a value if the field with the given `name` (attribute) has exactly the given value |
106
+
| url |`url`| The field under validation must be a valid URL |
107
+
108
+
#### Custom errors
109
+
you can bind the `Validator` object with your custom check function.
The previous listed errors already has it's errors messages (English)
130
+
```javascript
131
+
Validator.prototype.language= {
132
+
numeric:'The {label} must be a number.',
133
+
integer:'The {label} must be an integer.',
134
+
between_numeric:'The {label} must be between {param0} and {param1}.',
135
+
max_numeric:'The {label} may not be greater than {param0}.',
136
+
min_numeric:'The {label} must be at least {param0}.',
137
+
size_numeric:'The {label} must be {param0}.',
138
+
between:'The {label} must be between {param0} and {param1} characters.',
139
+
max:'The {label} may not be greater than {param0} characters.',
140
+
min:'The {label} must be at least {param0} characters.',
141
+
size:'The {label} must be {param0} characters.',
142
+
date:'The {label} must be a date after {param0}.',
143
+
before:'The {label} must be a date before {param0}.',
144
+
before_or_equal:'The {label} must be a date before or equal to {param0}.',
145
+
after:'The {label} must be a date after {param0}.',
146
+
after_or_equal:'The {label} must be a date after or equal to {param0}.',
147
+
age:'The age should be more than {param0}.',
148
+
email:'The {label} must be a valid email address.',
149
+
in:'The selected {label} is invalid.',
150
+
not_in:'The selected {label} is invalid.',
151
+
different:'The {label} and {otherLabel} must be different.',
152
+
required:'The {label} field is required..',
153
+
required_if:'The {label} field is required when {otherLabel} is filled.',
154
+
required_if_val:'The {label} field is required when {otherLabel} is {param0}',
155
+
same:'The {label} and {otherLabel} must match.',
156
+
url:'The {label} format is invalid.',
157
+
regex:'The {label} format is invalid.'
158
+
}
159
+
```
160
+
#### Bind error message
161
+
you can simply override the given messages using prototype object, and note that the key of the message is exactly the same of the function name, so when you add your custom validator you should add the suitable key language if you want to show the error
162
+
```javascript
163
+
Validator.prototype.language= {/* your custom error messages */}
164
+
```
165
+
or you can merge exiting errors with additional messages using options parameter in the constructor
166
+
```javascript
167
+
$(document).on('blur', '[data-validator]', function () {
168
+
newValidator($(this), {
169
+
language : {
170
+
valid_user_name :'The {label} should have a valid user name with length of {param0}'
0 commit comments