Class: ValidatorUtils::GeneralValidator
- Inherits:
-
Object
- Object
- ValidatorUtils::GeneralValidator
- Defined in:
- lib/ig-validator-utils.rb
Class Method Summary collapse
-
.validate_address(value) ⇒ Object
pL matches a single unicode letter pN matches a single unicode number allow points, comma, apostrophe, hyphen, spaces.
-
.validate_alpha_numeric(value) ⇒ Object
pL matches a single unicode letter pN matches a single unicode number.
-
.validate_base_64(value) ⇒ Object
validates base64 encoding (includes newline constants ‘n’).
- .validate_boolean(value) ⇒ Object
- .validate_email(value) ⇒ Object
- .validate_hex(value) ⇒ Object
- .validate_integer(value) ⇒ Object
-
.validate_mobile(value) ⇒ Object
accepts only numbers with international codes in the format +12 12345678.
-
.validate_password(value) ⇒ Object
At least one upper case letter At least one lower case letter At least one digit Minimum 6 in length Maximum 20 in length.
-
.validate_password_relaxed(value) ⇒ Object
Match any non-whitespace character Minimum 6 in length Maximum 20 in length.
-
.validate_public_ecdsa_key(value) ⇒ Object
for a 256-bit ECDSA curve, the uncompressed pubkey is 512 bits (256 bits of x, 256 bits of y, no sign bit).
- .validate_string(value) ⇒ Object
-
.validate_string_strict(value) ⇒ Object
pL matches a single unicode letter also allows space, points, apostrophe and hyphen.
- .validate_unix_datetime(value) ⇒ Object
- .validate_uri(value) ⇒ Object
-
.validate_username_strict(value) ⇒ Object
pL matches a single unicode letter also allows ‘.’, ‘-’, ‘_’, ‘@’ takes into account usernames that are email addresses.
- .validate_uuid(value) ⇒ Object
Class Method Details
.validate_address(value) ⇒ Object
pL matches a single unicode letter pN matches a single unicode number allow points, comma, apostrophe, hyphen, spaces
23 24 25 |
# File 'lib/ig-validator-utils.rb', line 23 def self.validate_address(value) value =~ /^[\p{L}\p{N} .,'-]+$/i end |
.validate_alpha_numeric(value) ⇒ Object
pL matches a single unicode letter pN matches a single unicode number
29 30 31 |
# File 'lib/ig-validator-utils.rb', line 29 def self.validate_alpha_numeric(value) value =~ /^[\p{L}\p{N}]+$/i end |
.validate_base_64(value) ⇒ Object
validates base64 encoding (includes newline constants ‘n’)
84 85 86 |
# File 'lib/ig-validator-utils.rb', line 84 def self.validate_base_64(value) value =~ /^[A-Za-z0-9+\/=\\]+={0,3}$/ end |
.validate_boolean(value) ⇒ Object
37 38 39 |
# File 'lib/ig-validator-utils.rb', line 37 def self.validate_boolean(value) !!value == value end |
.validate_email(value) ⇒ Object
92 93 94 |
# File 'lib/ig-validator-utils.rb', line 92 def self.validate_email(value) value =~ /^[\w+\-.]+@[a-z\d\-.]+\.[a-z]+$/ end |
.validate_hex(value) ⇒ Object
45 46 47 |
# File 'lib/ig-validator-utils.rb', line 45 def self.validate_hex(value) value =~ /^[a-f\d]{24}$/i end |
.validate_integer(value) ⇒ Object
33 34 35 |
# File 'lib/ig-validator-utils.rb', line 33 def self.validate_integer(value) Float(value) != nil rescue false end |
.validate_mobile(value) ⇒ Object
accepts only numbers with international codes in the format +12 12345678
97 98 99 100 101 |
# File 'lib/ig-validator-utils.rb', line 97 def self.validate_mobile(value) # strip out spaces first stripped = value.split.join stripped =~ /^(\+\d{1,3}[-]?)\d{8,12}$/ end |
.validate_password(value) ⇒ Object
At least one upper case letter At least one lower case letter At least one digit Minimum 6 in length Maximum 20 in length
54 55 56 |
# File 'lib/ig-validator-utils.rb', line 54 def self.validate_password(value) value =~ /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).{6,20}$/ end |
.validate_password_relaxed(value) ⇒ Object
Match any non-whitespace character Minimum 6 in length Maximum 20 in length
61 62 63 |
# File 'lib/ig-validator-utils.rb', line 61 def self.validate_password_relaxed(value) value =~ /^\S{6,20}$/ end |
.validate_public_ecdsa_key(value) ⇒ Object
for a 256-bit ECDSA curve, the uncompressed pubkey is 512 bits (256 bits of x, 256 bits of y, no sign bit). the compressed pubkey is 257 bits (256 bits of x, one bit of the sign of y). this equates to 32 bytes (ie: 256/8 = 32) + 1 (the sign) = 33
68 69 70 71 |
# File 'lib/ig-validator-utils.rb', line 68 def self.validate_public_ecdsa_key(value) decoded_key = Base64.decode64 value decoded_key.length == 33 end |
.validate_string(value) ⇒ Object
3 4 5 |
# File 'lib/ig-validator-utils.rb', line 3 def self.validate_string(value) value.to_s != '' end |
.validate_string_strict(value) ⇒ Object
pL matches a single unicode letter also allows space, points, apostrophe and hyphen
16 17 18 |
# File 'lib/ig-validator-utils.rb', line 16 def self.validate_string_strict(value) value =~ /^[\p{L} .'-]+$/i end |
.validate_unix_datetime(value) ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/ig-validator-utils.rb', line 73 def self.validate_unix_datetime(value) begin now = Date.today.to_time time_to_validate = Time.at value return time_to_validate > now rescue return false end end |
.validate_uri(value) ⇒ Object
88 89 90 |
# File 'lib/ig-validator-utils.rb', line 88 def self.validate_uri(value) value =~ /^(http|https):\/\/[a-z0-9]+([\-\.][a-z0-9]+)*\.[a-z]{2,13}(:[0-9]{1,5})?(\/.*)?$/ end |
.validate_username_strict(value) ⇒ Object
pL matches a single unicode letter also allows ‘.’, ‘-’, ‘_’, ‘@’ takes into account usernames that are email addresses
10 11 12 |
# File 'lib/ig-validator-utils.rb', line 10 def self.validate_username_strict(value) value =~ /^[\p{L} .-@_]+$/i end |
.validate_uuid(value) ⇒ Object
41 42 43 |
# File 'lib/ig-validator-utils.rb', line 41 def self.validate_uuid(value) value =~ /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i end |