class Assert::Assertions::Email(PropertyType)
Overview
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
Defined in:
assertions/email.crConstructors
Instance Method Summary
-
#default_message_template : String
Returns the default
#message_template
to use if no message is provided. -
#message : String
The message to display if
self
is not valid. -
#valid? : Bool
Returns
true
if a property satisfiesself
, otherwisefalse
.
Instance methods inherited from class Assert::Assertions::Assertion
default_message_template : String
default_message_template,
groups : Array(String)
groups,
message : String
message,
message_template : String
message_template,
property_name : String
property_name,
valid? : Bool
valid?
Constructor methods inherited from class Assert::Assertions::Assertion
new(property_name : String, message : String? = nil, groups : Array(String)? = nil)
new
Constructor Detail
def self.new(property_name : String, actual : Union(String, Nil), mode : EmailValidationMode = EmailValidationMode::Loose, normalizer : Proc(String, String)? = nil, message : String? = nil, groups : Array(String)? = nil)
#
Instance Method Detail
def default_message_template : String
#
Returns the default #message_template
to use if no message is provided.
def message : String
#
The message to display if self
is not valid.
NOTE This method is defined automatically, and is just present for documentation purposes.