Skip to content

Commit 703dd55

Browse files
committed
Added credit card validation and fixes for issue victorjonsson#127
1 parent 3121e62 commit 703dd55

15 files changed

+252
-70
lines changed

README.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,17 @@ particular form.
3838
</script>
3939
```
4040

41-
### Moving up to version 2.0
41+
### Support for HTML5
4242

43-
So what has changed since version 1.x?
43+
Since version 2.2 you can use this plugin as a fallback solution for the validation attributes in the HTML5 spec.
44+
Add the module `html5` to the module string and you can use the following native features:
45+
46+
**Attributes**: require, pattern, maxlength, min, max, placeholder
47+
48+
**Input types**: url, date, time, email, number
49+
50+
**Elements**: Use the element `datalist` to create input suggestions
4451

45-
* A whole bunch of validation functions have been added (see below).
46-
* A modular design have been introduced, which means that some validation functions is default and others is
47-
part of a module. This in turn lowers server and bandwidth costs.
48-
* You no longer need to prefix the validation rules with "validate_".
49-
* Error message position now defaults to "element".
50-
* The optional features (validateOnBlur and showHelpOnFocus) is now enabled by default.
51-
* The function $.validate(config) is introduced to reduce the amount of code that has to be written when initiating the form validation.
52-
* Demos and full documentation is now available at http://formvalidator.net/
5352

5453
### Default validators and features (no module needed)
5554
* **url**
@@ -75,7 +74,9 @@ Read the documentation for the default features at [http://formvalidator.net/#de
7574
### Module: security
7675
* **spamcheck**
7776
* **confirmation**
78-
* **strength***Validate the strength of a password (strength strength3)*
77+
* **creditcard**
78+
* **CVV**
79+
* **strength***Validate the strength of a password*
7980
* **backend***Validate value of input on server side*
8081

8182
Read the documentation for the security module at [http://formvalidator.net/#security-validators](http://formvalidator.net/#security-validators)
@@ -299,9 +300,11 @@ it calls jQ func **$.formUtils.validateInput** to validate the single input when
299300
* This plugin now serves as a html5 fallback. You can now use the native attributes to declare which type
300301
of validation that should be applied.
301302
* Use a template for error messages when having errorMessagePosition set to top
303+
* Added validation of credit card number and CVV to the security module
302304
* Event onElementValidate added
303305
* Use the attribute data-validation-confirm to declare which input that should be confirmed when using validation=confirmation (issue #112)
304306
* Validation "required" now supports inputs of type radio
307+
* $.validateForm is now deprecated, use $.isValid instead
305308

306309

307310
#### 2.1.47

form-validator/date.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @website http://formvalidator.net/#location-validators
1212
* @license Dual licensed under the MIT or GPL Version 2 licenses
13-
* @version 2.1.56
13+
* @version 2.1.63
1414
*/
1515
(function($) {
1616

form-validator/file.dev.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @website http://formvalidator.net/
1212
* @license Dual licensed under the MIT or GPL Version 2 licenses
13-
* @version 2.1.56
13+
* @version 2.1.63
1414
*/
1515
(function($, window) {
1616

@@ -45,7 +45,6 @@
4545
$.each(files, function(i, file) {
4646
valid = false;
4747
mime = file.type || '';
48-
alert(mime);
4948
$.each(allowedTypes, function(j, type) {
5049
valid = mime.indexOf(type) > -1;
5150
if( valid ) {

form-validator/file.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

form-validator/form-test.html

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
width: 375px;
2020
}
2121

22+
button, input[type="submit"], .button {
23+
margin-bottom: 8px;
24+
}
25+
2226
/* While server is being requested */
2327
form.validating-server-side {
2428
background: #F2F2F2;
@@ -170,6 +174,7 @@
170174
<label class="control-label">File validation</label>
171175
<input type="file" name="some-file1" class="form-control"
172176
data-validation="size mime required"
177+
data-validation-size-error-msg="The file cant be larger than 100kb"
173178
data-validation-error-msg="You must upload an image file"
174179
data-validation-allowing="jpg, png, ico"
175180
data-validation-max-size="100kb" />
@@ -180,7 +185,9 @@
180185
<input type="file" multiple="multiple" name="some-file2" class="form-control"
181186
data-validation="size mime required length"
182187
data-validation-length="min2"
183-
data-validation-error-msg="You must upload at least two image files"
188+
data-validation-size-error-msg="The images may be max 100kb"
189+
data-validation-length-error-msg="You have to upload at least (two) images"
190+
data-validation-error-msg="You have to upload at least two images"
184191
data-validation-allowing="jpg, png, ico"
185192
data-validation-max-size="100kb" />
186193
</div>
@@ -213,8 +220,19 @@
213220
<input type="checkbox" name="box" value="5" /> 5
214221
</label>
215222
</div>
216-
<p>
223+
<p style="line-height: 200%">
217224
<input type="submit" class="button">
225+
<br />
226+
<button class="button" type="button"
227+
onclick="alert('From a is ' + ( $('#form-a').isValid({}, {}, false) ? 'VALID':'NOT VALID'));">
228+
Test validation via js (<strong>without error messages</strong>)
229+
</button>
230+
<br />
231+
<button class="button" type="button"
232+
onclick="alert('From a is ' + ( $('#form-a').isValid() ? 'VALID':'NOT VALID'));">
233+
Test validation via js (showing error messages)
234+
</button>
235+
<br />
218236
<input type="reset" class="button">
219237
</p>
220238
</form>
@@ -285,7 +303,14 @@ <h2>HTML5 attributes</h2>
285303
</div>
286304
<div class="form-group">
287305
<label class="control-label">pattern="^([a-z]+)$"</label>
288-
<input type="text" pattern="^([a-z]+)$" required="required" />
306+
<input type="text" name="some-colorz" list="some-colorz" pattern="^([a-z]+)$" required="required" />
307+
<datalist id="some-colorz" style="display: none">
308+
<option value="Green">Green</option>
309+
<option value="Blue">Blue</option>
310+
<option value="Red">Red</option>
311+
<option value="Black">Black</option>
312+
<option value="White">White</option>
313+
</datalist>
289314
</div>
290315
<p>
291316
<input type="submit" class="button">

form-validator/html5.dev.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
*
1818
* @website http://formvalidator.net/
1919
* @license Dual licensed under the MIT or GPL Version 2 licenses
20-
* @version 2.1.56
20+
* @version 2.1.63
2121
*/
2222
(function($, window) {
2323

2424
"use strict";
2525

26-
var SUPPORTS_PLACEHOLDER = 'placeholder' in document.createElement('input'),
27-
SUPPORTS_DATALIST = 'options' in document.createElement('datalist');
26+
var SUPPORTS_PLACEHOLDER = 'placeholder' in document.createElement('INPUT'),
27+
SUPPORTS_DATALIST = 'options' in document.createElement('DATALIST');
2828

2929
$(window).bind('validatorsLoaded formValidationSetup', function(evt, $form) {
3030

@@ -92,10 +92,13 @@
9292
attrs['data-validation-length'] = 'max'+$input.attr('maxlength');
9393
}
9494

95+
console.log($input.html());
9596
if( !SUPPORTS_DATALIST && $input.attr('list') ) {
97+
console.log($input.attr('list'));
9698
var suggestions = [];
9799
$('#'+$input.attr('list')+' option').each(function() {
98-
suggestions.push($(this).attr('value'));
100+
var $opt = $(this);
101+
suggestions.push($opt.attr('value') || $opt.text());
99102
});
100103
$.formUtils.suggest( $input, suggestions );
101104
}

form-validator/html5.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)