jquery-form-validator-rails 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/README.md +30 -2
- data/app/assets/javascripts/date.dev.js +81 -0
- data/app/assets/javascripts/file.dev.js +195 -0
- data/app/assets/javascripts/file.js +1 -1
- data/app/assets/javascripts/form-test.html +422 -0
- data/app/assets/javascripts/html5.dev.js +144 -0
- data/app/assets/javascripts/html5.js +1 -1
- data/app/assets/javascripts/jquery.form-validator.js +229 -251
- data/app/assets/javascripts/jquery.form-validator.min.js +10 -0
- data/app/assets/javascripts/location.dev.js +78 -0
- data/app/assets/javascripts/qunit.html +635 -0
- data/app/assets/javascripts/security.dev.js +51 -24
- data/app/assets/javascripts/security.js +1 -1
- data/app/assets/javascripts/sweden.dev.js +1 -1
- data/app/assets/javascripts/uk.dev.js +1 -1
- data/lib/jquery/form/validator/rails/version.rb +1 -1
- metadata +21 -14
@@ -13,7 +13,7 @@
|
|
13
13
|
* - cvv
|
14
14
|
*
|
15
15
|
* @website http://formvalidator.net/#security-validators
|
16
|
-
* @version 2.
|
16
|
+
* @version 2.2.beta.50
|
17
17
|
*/
|
18
18
|
(function($, window) {
|
19
19
|
|
@@ -55,31 +55,37 @@
|
|
55
55
|
errorMessageKey: 'notConfirmed'
|
56
56
|
});
|
57
57
|
|
58
|
+
var creditCards = {
|
59
|
+
'amex' : [15,15],
|
60
|
+
'diners_club' : [14,14],
|
61
|
+
'cjb' : [16,16],
|
62
|
+
'laser' : [16,19],
|
63
|
+
'visa' : [16,16],
|
64
|
+
'mastercard' : [16,16],
|
65
|
+
'maestro' : [12,19],
|
66
|
+
'discover' : [16,16]
|
67
|
+
},
|
68
|
+
checkOnlyAmex = false,
|
69
|
+
allowsAmex = false;
|
70
|
+
|
58
71
|
/*
|
59
72
|
* Credit card
|
60
73
|
*/
|
61
74
|
$.formUtils.addValidator({
|
62
75
|
name : 'creditcard',
|
63
76
|
validatorFunction : function(value, $el, config, language, $form) {
|
64
|
-
var
|
65
|
-
'amex' : [15,15],
|
66
|
-
'diners_club' : [14,14],
|
67
|
-
'cjb' : [16,16],
|
68
|
-
'laser' : [16,19],
|
69
|
-
'visa' : [16,16],
|
70
|
-
'mastercard' : [16,16],
|
71
|
-
'maestro' : [12,19],
|
72
|
-
'discover' : [16,16]
|
73
|
-
},
|
74
|
-
allowing = $.split( $el.valAttr('allowing') || '' );
|
77
|
+
var allowing = $.split( $el.valAttr('allowing') || '' );
|
75
78
|
|
79
|
+
// Setup for cvv validation
|
80
|
+
allowsAmex = $.inArray('amex', allowing) > -1;
|
81
|
+
checkOnlyAmex = allowsAmex && allowing.length == 1;
|
76
82
|
|
77
83
|
// Correct length
|
78
84
|
if( allowing.length > 0 ) {
|
79
85
|
var hasValidLength = false;
|
80
86
|
$.each(allowing, function(i, cardName) {
|
81
|
-
if( cardName in
|
82
|
-
if( value.length >=
|
87
|
+
if( cardName in creditCards) {
|
88
|
+
if( value.length >= creditCards[cardName][0] && value.length <= creditCards[cardName][1]) {
|
83
89
|
hasValidLength = true;
|
84
90
|
return false;
|
85
91
|
}
|
@@ -126,7 +132,17 @@
|
|
126
132
|
$.formUtils.addValidator({
|
127
133
|
name : 'cvv',
|
128
134
|
validatorFunction : function(val) {
|
129
|
-
|
135
|
+
if( val.replace(/[0-9]/g, '') === '' ) {
|
136
|
+
val = val + '';
|
137
|
+
if( checkOnlyAmex ) {
|
138
|
+
return val.length == 4;
|
139
|
+
} else if( allowsAmex ) {
|
140
|
+
return val.length == 3 || val.length == 4;
|
141
|
+
} else {
|
142
|
+
return val.length == 3;
|
143
|
+
}
|
144
|
+
}
|
145
|
+
return false;
|
130
146
|
},
|
131
147
|
errorMessage : '',
|
132
148
|
errorMessageKey: 'badCVV'
|
@@ -317,13 +333,21 @@
|
|
317
333
|
});
|
318
334
|
|
319
335
|
var requestServer = function(serverURL, $element, val, conf, callback) {
|
336
|
+
var reqParams = $element.valAttr('req-params');
|
337
|
+
if( !reqParams )
|
338
|
+
reqParams = {};
|
339
|
+
if( typeof reqParams == 'string' ) {
|
340
|
+
reqParams = $.parseJSON(reqParams);
|
341
|
+
}
|
342
|
+
reqParams[$element.attr('name')] = val;
|
343
|
+
|
320
344
|
$.ajax({
|
321
345
|
url : serverURL,
|
322
346
|
type : 'POST',
|
323
347
|
cache : false,
|
324
|
-
data :
|
348
|
+
data : reqParams,
|
325
349
|
dataType : 'json',
|
326
|
-
error : function(error) {
|
350
|
+
error : function(error, err) {
|
327
351
|
alert('Server validation failed due to: '+error.statusText);
|
328
352
|
if( window.JSON && window.JSON.stringify ) {
|
329
353
|
alert(window.JSON.stringify(error));
|
@@ -337,8 +361,6 @@
|
|
337
361
|
$element.valAttr('backend-invalid', 'true');
|
338
362
|
if(response.message)
|
339
363
|
$element.attr(conf.validationErrorMsgAttribute, response.message);
|
340
|
-
else
|
341
|
-
$element.removeAttr(conf.validationErrorMsgAttribute);
|
342
364
|
}
|
343
365
|
|
344
366
|
if( !$element.valAttr('has-keyup-event') ) {
|
@@ -348,8 +370,7 @@
|
|
348
370
|
if( evt.keyCode != 9 && evt.keyCode != 16 ) {
|
349
371
|
$(this)
|
350
372
|
.valAttr('backend-valid', false)
|
351
|
-
.valAttr('backend-invalid', false)
|
352
|
-
.removeAttr(conf.validationErrorMsgAttribute);
|
373
|
+
.valAttr('backend-invalid', false);
|
353
374
|
}
|
354
375
|
});
|
355
376
|
}
|
@@ -392,14 +413,18 @@
|
|
392
413
|
return true;
|
393
414
|
else if(backendInvalid)
|
394
415
|
return false;
|
416
|
+
else if($.formUtils.eventType == 'keyup')
|
417
|
+
return null;
|
395
418
|
|
396
419
|
if($.formUtils.isValidatingEntireForm) {
|
420
|
+
|
397
421
|
$form
|
398
422
|
.bind('submit', disableFormSubmit)
|
399
423
|
.addClass('validating-server-side')
|
400
424
|
.addClass('on-blur');
|
401
425
|
|
402
426
|
$el.addClass('validating-server-side');
|
427
|
+
$.formUtils.haltValidation = true;
|
403
428
|
|
404
429
|
requestServer(serverURL, $el, val, conf, function() {
|
405
430
|
$form
|
@@ -410,12 +435,14 @@
|
|
410
435
|
$form.unbind('submit', disableFormSubmit);
|
411
436
|
$el.removeClass('validating-server-side');
|
412
437
|
|
438
|
+
$el.valAttr('value-length', val.length);
|
439
|
+
|
413
440
|
// fire submission again!
|
441
|
+
$.formUtils.haltValidation = false;
|
414
442
|
$form.trigger('submit');
|
415
443
|
});
|
416
444
|
|
417
|
-
|
418
|
-
return false;
|
445
|
+
return null;
|
419
446
|
|
420
447
|
} else {
|
421
448
|
// validaiton on blur
|
@@ -426,7 +453,7 @@
|
|
426
453
|
$el.removeClass('validating-server-side');
|
427
454
|
$el.trigger('blur');
|
428
455
|
});
|
429
|
-
return
|
456
|
+
return null;
|
430
457
|
}
|
431
458
|
},
|
432
459
|
errorMessage : '',
|
@@ -1 +1 @@
|
|
1
|
-
(function($,window){"use strict";$.formUtils.addValidator({name:"spamcheck",validatorFunction:function(val,$el,config){var attr=$el.valAttr("captcha");return attr===val},errorMessage:"",errorMessageKey:"badSecurityAnswer"});$.formUtils.addValidator({name:"confirmation",validatorFunction:function(value,$el,config,language,$form){var conf="",confInputName=$el.valAttr("confirm")||$el.attr("name")+"_confirmation",confInput=$form.find('input[name="'+confInputName+'"]').eq(0);if(confInput){conf=confInput.val()}else{console.warn('Could not find an input with name "'+confInputName+'"')}return value===conf},errorMessage:"",errorMessageKey:"notConfirmed"})
|
1
|
+
(function($,window){"use strict";$.formUtils.addValidator({name:"spamcheck",validatorFunction:function(val,$el,config){var attr=$el.valAttr("captcha");return attr===val},errorMessage:"",errorMessageKey:"badSecurityAnswer"});$.formUtils.addValidator({name:"confirmation",validatorFunction:function(value,$el,config,language,$form){var conf="",confInputName=$el.valAttr("confirm")||$el.attr("name")+"_confirmation",confInput=$form.find('input[name="'+confInputName+'"]').eq(0);if(confInput){conf=confInput.val()}else{console.warn('Could not find an input with name "'+confInputName+'"')}return value===conf},errorMessage:"",errorMessageKey:"notConfirmed"});var creditCards={amex:[15,15],diners_club:[14,14],cjb:[16,16],laser:[16,19],visa:[16,16],mastercard:[16,16],maestro:[12,19],discover:[16,16]},checkOnlyAmex=false,allowsAmex=false;$.formUtils.addValidator({name:"creditcard",validatorFunction:function(value,$el,config,language,$form){var allowing=$.split($el.valAttr("allowing")||"");allowsAmex=$.inArray("amex",allowing)>-1;checkOnlyAmex=allowsAmex&&allowing.length==1;if(allowing.length>0){var hasValidLength=false;$.each(allowing,function(i,cardName){if(cardName in creditCards){if(value.length>=creditCards[cardName][0]&&value.length<=creditCards[cardName][1]){hasValidLength=true;return false}}else{console.warn('Use of unknown credit card "'+cardName+'"')}});if(!hasValidLength)return false}if(value.replace(new RegExp("[0-9]","g"),"")!==""){return false}var checkSum=0;$.each(value.split("").reverse(),function(i,digit){digit=parseInt(digit,10);if(i%2===0){checkSum+=digit}else{digit*=2;if(digit<10){checkSum+=digit}else{checkSum+=digit-9}}});return checkSum%10===0},errorMessage:"",errorMessageKey:"badCreditCard"});$.formUtils.addValidator({name:"cvv",validatorFunction:function(val){if(val.replace(/[0-9]/g,"")===""){val=val+"";if(checkOnlyAmex){return val.length==4}else if(allowsAmex){return val.length==3||val.length==4}else{return val.length==3}}return false},errorMessage:"",errorMessageKey:"badCVV"});$.formUtils.addValidator({name:"strength",validatorFunction:function(val,$el,conf){var requiredStrength=$el.valAttr("strength");if(requiredStrength&&requiredStrength>3)requiredStrength=3;return $.formUtils.validators.validate_strength.calculatePasswordStrength(val)>=requiredStrength},errorMessage:"",errorMessageKey:"badStrength",calculatePasswordStrength:function(password){if(password.length<4){return 0}var score=0;var checkRepetition=function(pLen,str){var res="";for(var i=0;i<str.length;i++){var repeated=true;for(var j=0;j<pLen&&j+i+pLen<str.length;j++){repeated=repeated&&str.charAt(j+i)==str.charAt(j+i+pLen)}if(j<pLen){repeated=false}if(repeated){i+=pLen-1;repeated=false}else{res+=str.charAt(i)}}return res};score+=password.length*4;score+=(checkRepetition(1,password).length-password.length)*1;score+=(checkRepetition(2,password).length-password.length)*1;score+=(checkRepetition(3,password).length-password.length)*1;score+=(checkRepetition(4,password).length-password.length)*1;if(password.match(/(.*[0-9].*[0-9].*[0-9])/)){score+=5}if(password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)){score+=5}if(password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)){score+=10}if(password.match(/([a-zA-Z])/)&&password.match(/([0-9])/)){score+=15}if(password.match(/([!,@,#,$,%,^,&,*,?,_,~])/)&&password.match(/([0-9])/)){score+=15}if(password.match(/([!,@,#,$,%,^,&,*,?,_,~])/)&&password.match(/([a-zA-Z])/)){score+=15}if(password.match(/^\w+$/)||password.match(/^\d+$/)){score-=10}if(score<0){score=0}if(score>100){score=100}if(score<20){return 0}else if(score<40){return 1}else if(score<=60){return 2}else{return 3}},strengthDisplay:function($el,options){var config={fontSize:"12pt",padding:"4px",bad:"Very bad",weak:"Weak",good:"Good",strong:"Strong"};if(options){$.extend(config,options)}$el.bind("keyup",function(){var val=$(this).val();var $parent=typeof config.parent=="undefined"?$(this).parent():$(config.parent);var $displayContainer=$parent.find(".strength-meter");if($displayContainer.length==0){$displayContainer=$("<span></span>");$displayContainer.addClass("strength-meter").appendTo($parent)}if(!val){$displayContainer.hide()}else{$displayContainer.show()}var strength=$.formUtils.validators.validate_strength.calculatePasswordStrength(val);var css={background:"pink",color:"#FF0000",fontWeight:"bold",border:"red solid 1px",borderWidth:"0px 0px 4px",display:"inline-block",fontSize:config.fontSize,padding:config.padding};var text=config.bad;if(strength==1){text=config.weak}else if(strength==2){css.background="lightyellow";css.borderColor="yellow";css.color="goldenrod";text=config.good}else if(strength>=3){css.background="lightgreen";css.borderColor="darkgreen";css.color="darkgreen";text=config.strong}$displayContainer.css(css).text(text)})}});var requestServer=function(serverURL,$element,val,conf,callback){var reqParams=$element.valAttr("req-params");if(!reqParams)reqParams={};if(typeof reqParams=="string"){reqParams=$.parseJSON(reqParams)}reqParams[$element.attr("name")]=val;$.ajax({url:serverURL,type:"POST",cache:false,data:reqParams,dataType:"json",error:function(error,err){alert("Server validation failed due to: "+error.statusText);if(window.JSON&&window.JSON.stringify){alert(window.JSON.stringify(error))}},success:function(response){if(response.valid){$element.valAttr("backend-valid","true")}else{$element.valAttr("backend-invalid","true");if(response.message)$element.attr(conf.validationErrorMsgAttribute,response.message)}if(!$element.valAttr("has-keyup-event")){$element.valAttr("has-keyup-event","1").bind("keyup",function(evt){if(evt.keyCode!=9&&evt.keyCode!=16){$(this).valAttr("backend-valid",false).valAttr("backend-invalid",false)}})}callback()}})},disableFormSubmit=function(){return false};$.formUtils.addValidator({name:"server",validatorFunction:function(val,$el,conf,lang,$form){var backendValid=$el.valAttr("backend-valid"),backendInvalid=$el.valAttr("backend-invalid"),serverURL=document.location.href;if($el.valAttr("url")){serverURL=$el.valAttr("url")}else if("serverURL"in conf){serverURL=conf.backendUrl}if(backendValid)return true;else if(backendInvalid)return false;else if($.formUtils.eventType=="keyup")return null;if($.formUtils.isValidatingEntireForm){$form.bind("submit",disableFormSubmit).addClass("validating-server-side").addClass("on-blur");$el.addClass("validating-server-side");$.formUtils.haltValidation=true;requestServer(serverURL,$el,val,conf,function(){$form.removeClass("validating-server-side").removeClass("on-blur").get(0).onsubmit=function(){};$form.unbind("submit",disableFormSubmit);$el.removeClass("validating-server-side");$el.valAttr("value-length",val.length);$.formUtils.haltValidation=false;$form.trigger("submit")});return null}else{$form.addClass("validating-server-side");$el.addClass("validating-server-side");requestServer(serverURL,$el,val,conf,function(){$form.removeClass("validating-server-side");$el.removeClass("validating-server-side");$el.trigger("blur")});return null}},errorMessage:"",errorMessageKey:"badBackend",validateOnKeyUp:false});$.fn.displayPasswordStrength=function(conf){new $.formUtils.validators.validate_strength.strengthDisplay(this,conf);return this}})(jQuery,window);
|
metadata
CHANGED
@@ -1,61 +1,61 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jquery-form-validator-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gustaf Lindqvist
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0.14'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.14'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: railties
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '3.2'
|
34
|
-
- - <
|
34
|
+
- - "<"
|
35
35
|
- !ruby/object:Gem::Version
|
36
36
|
version: '5.0'
|
37
37
|
type: :runtime
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
|
-
- -
|
41
|
+
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: '3.2'
|
44
|
-
- - <
|
44
|
+
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '5.0'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bundler
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- - ~>
|
51
|
+
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '1.0'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- - ~>
|
58
|
+
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '1.0'
|
61
61
|
description: Integrate the jQuery Form Validator plugin into the Rails asset pipeline
|
@@ -65,17 +65,24 @@ executables: []
|
|
65
65
|
extensions: []
|
66
66
|
extra_rdoc_files: []
|
67
67
|
files:
|
68
|
-
- .gitignore
|
68
|
+
- ".gitignore"
|
69
69
|
- CHANGELOG.md
|
70
70
|
- Gemfile
|
71
71
|
- LICENSE
|
72
72
|
- README.md
|
73
73
|
- Rakefile
|
74
|
+
- app/assets/javascripts/date.dev.js
|
74
75
|
- app/assets/javascripts/date.js
|
76
|
+
- app/assets/javascripts/file.dev.js
|
75
77
|
- app/assets/javascripts/file.js
|
78
|
+
- app/assets/javascripts/form-test.html
|
79
|
+
- app/assets/javascripts/html5.dev.js
|
76
80
|
- app/assets/javascripts/html5.js
|
77
81
|
- app/assets/javascripts/jquery.form-validator.js
|
82
|
+
- app/assets/javascripts/jquery.form-validator.min.js
|
83
|
+
- app/assets/javascripts/location.dev.js
|
78
84
|
- app/assets/javascripts/location.js
|
85
|
+
- app/assets/javascripts/qunit.html
|
79
86
|
- app/assets/javascripts/security.dev.js
|
80
87
|
- app/assets/javascripts/security.js
|
81
88
|
- app/assets/javascripts/sweden.dev.js
|
@@ -97,17 +104,17 @@ require_paths:
|
|
97
104
|
- lib
|
98
105
|
required_ruby_version: !ruby/object:Gem::Requirement
|
99
106
|
requirements:
|
100
|
-
- -
|
107
|
+
- - ">="
|
101
108
|
- !ruby/object:Gem::Version
|
102
109
|
version: '0'
|
103
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
111
|
requirements:
|
105
|
-
- -
|
112
|
+
- - ">="
|
106
113
|
- !ruby/object:Gem::Version
|
107
114
|
version: '0'
|
108
115
|
requirements: []
|
109
116
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.3
|
117
|
+
rubygems_version: 2.4.3
|
111
118
|
signing_key:
|
112
119
|
specification_version: 4
|
113
120
|
summary: jQuery Form Validator is a feature rich jQuery plugin that makes it easy
|