class

Assert::Assertions::Email(PropertyType)

Inherits Assert::Assertions::Assertion / Reference / Object

Validates a property is a properly formatted email.

Optional Arguments

  • mode - Which validation pattern to use. See EmailValidationMode.
  • normalizer - Execute a Proc to alter actual before checking its validity.

Example

class Example
  include Assert

  def initialize; end

  @[Assert::Email]
  property loose_email : String = "example@-example.com"

  @[Assert::Email(mode: :html5)]
  property strict_email : String = "example@example.co.uk"

  @[Assert::Email(mode: :html5, normalizer: ->(actual : String) { actual.strip })]
  property strict_email_normalizer : String = "  example@example.co.uk  "
end

Example.new.valid? # => true

Constructors

new(property_name : String, actual : Union(String, Nil), mode : EmailValidationMode = EmailValidationMode::Loose, normalizer : Proc(String, String) | Nil = nil, message : String | Nil = nil, groups : Array(String) | Nil = nil)
Source

Instance methods

default_message_template

Returns the default #message_template to use if no message is provided.

Source
message

The message to display if self is not valid.

NOTE: This method is defined automatically, and is just present for documentation purposes.

Source
valid?

Returns true if a property satisfies self, otherwise false.

Source

Nested types