defra_ruby_validators 2.5.1 → 2.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/config/locales/defra_ruby/validators/mobile_phone_number_validator/en.yml +7 -0
- data/lib/defra_ruby/validators/companies_house_number_validator.rb +1 -2
- data/lib/defra_ruby/validators/mobile_phone_number_validator.rb +32 -0
- data/lib/defra_ruby/validators/version.rb +1 -1
- data/lib/defra_ruby/validators.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54f780cf89fcc1888cd3b9af95707c6e3ac2a0d0dcd1e304ab6d9b2933b69ef9
|
4
|
+
data.tar.gz: 895551a30493fb79367289728c28e7e09873c1c6def93e685c70f7076b67f46c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '07863b0bde9327c8384a93b8e1c681b02ef7fedce040a36d4f17aa9435a4783e4db51fcf41a29469ea3b6d9599324b89f8ab5c3c830040b563894db33449d8e9'
|
7
|
+
data.tar.gz: 4e07b525aae83437d5ad450e4e3989f402caf04346efc130543440a41084e2a4ecc48168894f88e261fc66c269aa48389282dedd17b2031ce0a889924b99720c
|
data/README.md
CHANGED
@@ -144,6 +144,16 @@ Add it to your model or form object using
|
|
144
144
|
validates :phone_number, "defra_ruby/validators/phone_number": true
|
145
145
|
```
|
146
146
|
|
147
|
+
### Mobile phone number
|
148
|
+
|
149
|
+
This validator checks the value is present, is not too long (15 is th maximum length for any phone number), is a mobile phone number, and is in the correct format as per [E.164](https://en.wikipedia.org/wiki/E.164) (we use [phonelib](https://github.com/daddyz/phonelib) to check the format).
|
150
|
+
|
151
|
+
Add it to your model or form object using
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
validates :mobile_phone_number, "defra_ruby/validators/mobile_phone_number": true
|
155
|
+
```
|
156
|
+
|
147
157
|
### Position
|
148
158
|
|
149
159
|
This validator checks the value provided for 'position' i.e. someones role or title within an organisation. This is an optional field so the validator has to handle the value being blank. If it's not then it can be no longer than 70 characters and only include letters, spaces, commas, full stops, hyphens and apostrophes else it will return an error.
|
@@ -9,9 +9,8 @@ module DefraRuby
|
|
9
9
|
# SC534714, CE000958
|
10
10
|
# IP00141R, IP27702R, SP02252R
|
11
11
|
# https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/426891/uniformResourceIdentifiersCustomerGuide.pdf
|
12
|
-
VALID_COMPANIES_HOUSE_REGISTRATION_NUMBER_REGEX =
|
12
|
+
VALID_COMPANIES_HOUSE_REGISTRATION_NUMBER_REGEX =
|
13
13
|
/\A(\d{8,8}$)|([a-zA-Z]{2}\d{6}$)|([a-zA-Z]{2}\d{5}[a-zA-Z]{1}$)\z/i
|
14
|
-
).freeze
|
15
14
|
|
16
15
|
def validate_each(record, attribute, value)
|
17
16
|
return false unless value_is_present?(record, attribute, value)
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "phonelib"
|
4
|
+
|
5
|
+
module DefraRuby
|
6
|
+
module Validators
|
7
|
+
class MobilePhoneNumberValidator < BaseValidator
|
8
|
+
include CanValidatePresence
|
9
|
+
include CanValidateLength
|
10
|
+
|
11
|
+
MAX_LENGTH = 15
|
12
|
+
|
13
|
+
def validate_each(record, attribute, value)
|
14
|
+
return false unless value_is_present?(record, attribute, value)
|
15
|
+
return false unless value_is_not_too_long?(record, attribute, value, MAX_LENGTH)
|
16
|
+
|
17
|
+
valid_format?(record, attribute, value)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def valid_format?(record, attribute, value)
|
23
|
+
Phonelib.default_country = "GB"
|
24
|
+
return true if Phonelib.valid?(value) && Phonelib.parse(value).type == :mobile
|
25
|
+
|
26
|
+
add_validation_error(record, attribute, :invalid_format)
|
27
|
+
false
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -18,6 +18,7 @@ require_relative "validators/email_validator"
|
|
18
18
|
require_relative "validators/grid_reference_validator"
|
19
19
|
require_relative "validators/location_validator"
|
20
20
|
require_relative "validators/phone_number_validator"
|
21
|
+
require_relative "validators/mobile_phone_number_validator"
|
21
22
|
require_relative "validators/position_validator"
|
22
23
|
require_relative "validators/token_validator"
|
23
24
|
require_relative "validators/true_false_validator"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: defra_ruby_validators
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.5.
|
4
|
+
version: 2.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Defra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-06-
|
11
|
+
date: 2023-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -125,6 +125,7 @@ files:
|
|
125
125
|
- config/locales/defra_ruby/validators/email_validator/en.yml
|
126
126
|
- config/locales/defra_ruby/validators/grid_reference_validator/en.yml
|
127
127
|
- config/locales/defra_ruby/validators/location_validator/en.yml
|
128
|
+
- config/locales/defra_ruby/validators/mobile_phone_number_validator/en.yml
|
128
129
|
- config/locales/defra_ruby/validators/past_date_validator/en.yml
|
129
130
|
- config/locales/defra_ruby/validators/phone_number_validator/en.yml
|
130
131
|
- config/locales/defra_ruby/validators/position_validator/en.yml
|
@@ -144,6 +145,7 @@ files:
|
|
144
145
|
- lib/defra_ruby/validators/engine.rb
|
145
146
|
- lib/defra_ruby/validators/grid_reference_validator.rb
|
146
147
|
- lib/defra_ruby/validators/location_validator.rb
|
148
|
+
- lib/defra_ruby/validators/mobile_phone_number_validator.rb
|
147
149
|
- lib/defra_ruby/validators/past_date_validator.rb
|
148
150
|
- lib/defra_ruby/validators/phone_number_validator.rb
|
149
151
|
- lib/defra_ruby/validators/position_validator.rb
|