Class: Apes::Validators::PhoneValidator

Inherits:
BaseValidator
  • Object
show all
Defined in:
lib/apes/validators.rb

Overview

Validates phones.

Constant Summary

VALID_REGEX =

The pattern to recognize valid phones.

/^(
  ((\+|00)\d)? # International prefix
  ([0-9\-\s\/\(\)]{7,}) # All the rest
)$/mx

Instance Method Summary (collapse)

Methods inherited from BaseValidator

#validate_each

Constructor Details

- (Apes::Validators::PhoneValidator) initialize(options)

Creates a new validator.

Parameters:

  • options (Hash)

    The options for the validations.



145
146
147
# File 'lib/apes/validators.rb', line 145

def initialize(options)
  super(options.reverse_merge(default_message: "must be a valid phone"))
end

Instance Method Details

- (Boolean) check_valid?(value)

Checks if the value is valid for this validator.

Parameters:

  • value (Object)

    The value to validate.

Returns:

  • (Boolean)

    true if the value is valid, false otherwise.



153
154
155
# File 'lib/apes/validators.rb', line 153

def check_valid?(value)
  value.blank? || value =~ VALID_REGEX
end