ico-validator 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +3 -1
- data/CHANGELOG.md +4 -0
- data/Gemfile +5 -0
- data/README.md +11 -0
- data/Rakefile +2 -1
- data/app/assets/javascripts/ico-validator.js +52 -0
- data/ico-validator.gemspec +1 -1
- data/lib/ico-validator.rb +1 -0
- data/lib/ico-validator/engine.rb +4 -0
- data/spec/javascripts/support/jasmine.yml +5 -0
- data/spec/javascripts/support/jasmine_helper.rb +15 -0
- data/spec/javascripts/validator_spec.js +18 -0
- data/spec/spec_helper.rb +1 -0
- metadata +11 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6cd1b0fb28c0955404b04e7508c5b8cfce2c0b75
|
4
|
+
data.tar.gz: c4ae1c9962c5221705327bb67af973f4aeb60cc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3c3f4cdd367dbe7e200bdb1e1992fa5914247dcf23b9b9e0bd82a508b8e16083ac368f3e717235fc7479a5b810c4cd9750ebbfb23e17c7c1507749830d3a17c
|
7
|
+
data.tar.gz: 26f387d947bcd1d3aeb67cb861ba217623ad85ba25444b7ee62fd5b44ec18151ee70cc63de79294fd68ef7e52cf1e221daca02c9d329754787c5ac252cd62083
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -14,6 +14,17 @@ validates :ico,
|
|
14
14
|
|
15
15
|
```
|
16
16
|
|
17
|
+
### JS validation
|
18
|
+
```js
|
19
|
+
application.js
|
20
|
+
//= require ico-validator
|
21
|
+
```
|
22
|
+
```ruby
|
23
|
+
<%= form_for(...) do |f| %>
|
24
|
+
<%= f.text_field :ico, class: 'ico-validate' %>
|
25
|
+
<% end %>
|
26
|
+
```
|
27
|
+
|
17
28
|
### What is validated
|
18
29
|
|
19
30
|
* ICO length - must be exactly 8 characters
|
data/Rakefile
CHANGED
@@ -0,0 +1,52 @@
|
|
1
|
+
var ico_validator = {
|
2
|
+
valid_ico: function(value) {
|
3
|
+
return value.length === 8 && value.match(/^\d+$/) && ico_validator.last_number_valid(value);
|
4
|
+
},
|
5
|
+
last_number_valid: function(value) {
|
6
|
+
return parseInt(value[7], 10) === ico_validator.calculate_valid_last_number(value);
|
7
|
+
},
|
8
|
+
calculate_valid_last_number: function(value) {
|
9
|
+
var sum = 0;
|
10
|
+
for( var i = 0; i <= 6; i++ ) {
|
11
|
+
sum += value[i] * (8 - i);
|
12
|
+
}
|
13
|
+
var mod = sum % 11;
|
14
|
+
if( mod === 0 || mod === 10 ) {
|
15
|
+
return 1;
|
16
|
+
}
|
17
|
+
if( mod === 1 ) {
|
18
|
+
return 0;
|
19
|
+
}
|
20
|
+
return 11 - mod;
|
21
|
+
}
|
22
|
+
};
|
23
|
+
|
24
|
+
jQuery( function($) {
|
25
|
+
var ico_fields = $('.ico-validate');
|
26
|
+
|
27
|
+
function validate(el) {
|
28
|
+
var value = $(el).val();
|
29
|
+
if( ico_validator.valid_ico(value) ) {
|
30
|
+
$(el).parent().removeClass('field_with_errors').removeClass('error');
|
31
|
+
} else {
|
32
|
+
$(el).parent().addClass('field_with_errors').addClass('error');
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
ico_fields.on('change', function() {
|
37
|
+
validate(this);
|
38
|
+
});
|
39
|
+
|
40
|
+
ico_fields.on('keyup', function() {
|
41
|
+
validate(this);
|
42
|
+
});
|
43
|
+
|
44
|
+
ico_fields.closest('form').on('submit', function() {
|
45
|
+
var wrong = $(this).find('.field_with_errors .ico-validate');
|
46
|
+
if( wrong.length <= 0 ) {
|
47
|
+
return;
|
48
|
+
}
|
49
|
+
wrong.focus();
|
50
|
+
return false;
|
51
|
+
});
|
52
|
+
});
|
data/ico-validator.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'ico-validator'
|
7
|
-
spec.version = '0.
|
7
|
+
spec.version = '0.2.0'
|
8
8
|
spec.authors = ['Premysl Donat']
|
9
9
|
spec.email = ['donat@uol.cz']
|
10
10
|
spec.summary = %q{Rails validator for validating format of czech identification number = IC}
|
data/lib/ico-validator.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
#Use this file to set/override Jasmine configuration options
|
2
|
+
#You can remove it if you don't need it.
|
3
|
+
#This file is loaded *after* jasmine.yml is interpreted.
|
4
|
+
#
|
5
|
+
#Example: using a different boot file.
|
6
|
+
#Jasmine.configure do |config|
|
7
|
+
# config.boot_dir = '/absolute/path/to/boot_dir'
|
8
|
+
# config.boot_files = lambda { ['/absolute/path/to/boot_dir/file.js'] }
|
9
|
+
#end
|
10
|
+
#
|
11
|
+
#Example: prevent PhantomJS auto install, uses PhantomJS already on your path.
|
12
|
+
#Jasmine.configure do |config|
|
13
|
+
# config.prevent_phantom_js_auto_install = true
|
14
|
+
#end
|
15
|
+
#
|
@@ -0,0 +1,18 @@
|
|
1
|
+
describe("ICO validator", function() {
|
2
|
+
var ico_list, i;
|
3
|
+
ico_list = ['61499609', '25275500', '29233011'];
|
4
|
+
for( i in ico_list ) if( ico_list.hasOwnProperty(i) ) {
|
5
|
+
ico_valid = ico_list[i];
|
6
|
+
it("ICO " + ico_valid + " is valid", function() {
|
7
|
+
expect(ico_validator.valid_ico(ico_valid)).toBeTruthy();
|
8
|
+
});
|
9
|
+
}
|
10
|
+
ico_list = [null, '', '1', 123, '1111111X', '00000000', '614996097', '123456789'];
|
11
|
+
for( i in ico_list ) if( ico_list.hasOwnProperty(i) ) {
|
12
|
+
ico_invalid = ico_list[i];
|
13
|
+
it("ICO is invalid with value " + ico_invalid, function() {
|
14
|
+
expect(ico_validator.valid_ico(ico_invalid)).toBeFalsy();
|
15
|
+
});
|
16
|
+
}
|
17
|
+
});
|
18
|
+
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ico-validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Premysl Donat
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -95,12 +95,17 @@ files:
|
|
95
95
|
- LICENSE
|
96
96
|
- README.md
|
97
97
|
- Rakefile
|
98
|
+
- app/assets/javascripts/ico-validator.js
|
98
99
|
- ico-validator.gemspec
|
99
100
|
- lib/ico-validator.rb
|
101
|
+
- lib/ico-validator/engine.rb
|
100
102
|
- lib/ico-validator/ico_validator.rb
|
101
103
|
- lib/locale/cs.yml
|
102
104
|
- lib/locale/en.yml
|
103
105
|
- spec/ico_validator_spec.rb
|
106
|
+
- spec/javascripts/support/jasmine.yml
|
107
|
+
- spec/javascripts/support/jasmine_helper.rb
|
108
|
+
- spec/javascripts/validator_spec.js
|
104
109
|
- spec/spec_helper.rb
|
105
110
|
homepage: http://www.uol.cz
|
106
111
|
licenses:
|
@@ -122,11 +127,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
127
|
version: '0'
|
123
128
|
requirements: []
|
124
129
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.
|
130
|
+
rubygems_version: 2.4.5
|
126
131
|
signing_key:
|
127
132
|
specification_version: 4
|
128
133
|
summary: Rails validator for validating format of czech identification number = IC
|
129
134
|
test_files:
|
130
135
|
- spec/ico_validator_spec.rb
|
136
|
+
- spec/javascripts/support/jasmine.yml
|
137
|
+
- spec/javascripts/support/jasmine_helper.rb
|
138
|
+
- spec/javascripts/validator_spec.js
|
131
139
|
- spec/spec_helper.rb
|
132
|
-
has_rdoc:
|