Class: ValidatorUtils::GeneralValidator
- Inherits:
-
Object
- Object
- ValidatorUtils::GeneralValidator
- Defined in:
- lib/ig-validator-utils.rb
Class Method Summary collapse
-
.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_password(value) ⇒ Object
At least one upper case letter At least one lower case letter At least one digit Minimum 6 in length Maximum 12 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 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_base_64(value) ⇒ Object
validates base64 encoding (includes newline constants ‘n’)
64 65 66 |
# File 'lib/ig-validator-utils.rb', line 64 def self.validate_base_64(value) value =~ /^[A-Za-z0-9+\/=\\]+={0,3}$/ end |
.validate_boolean(value) ⇒ Object
24 25 26 |
# File 'lib/ig-validator-utils.rb', line 24 def self.validate_boolean(value) !!value == value end |
.validate_email(value) ⇒ Object
72 73 74 |
# File 'lib/ig-validator-utils.rb', line 72 def self.validate_email(value) value =~ /^[\w+\-.]+@[a-z\d\-.]+\.[a-z]+$/ end |
.validate_hex(value) ⇒ Object
32 33 34 |
# File 'lib/ig-validator-utils.rb', line 32 def self.validate_hex(value) value =~ /^[a-f\d]{24}$/i end |
.validate_integer(value) ⇒ Object
20 21 22 |
# File 'lib/ig-validator-utils.rb', line 20 def self.validate_integer(value) Float(value) != nil rescue false 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 12 in length
41 42 43 |
# File 'lib/ig-validator-utils.rb', line 41 def self.validate_password(value) value =~ /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).{6,12}$/ 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
48 49 50 51 |
# File 'lib/ig-validator-utils.rb', line 48 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 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
53 54 55 56 57 58 59 60 61 |
# File 'lib/ig-validator-utils.rb', line 53 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
68 69 70 |
# File 'lib/ig-validator-utils.rb', line 68 def self.validate_uri(value) value =~ /^(http|https):\/\/[a-z0-9]+([\-\.][a-z0-9]+)*\.[a-z]{2,5}(:[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
28 29 30 |
# File 'lib/ig-validator-utils.rb', line 28 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 |