module Amber::Support::TextFormats

Overview

Checks for the text formats Amber validates, each one a single left-to-right pass over the bytes. Their cost grows with the length of the text whatever the text contains, and they use no regex engine.

Defined in:

amber/support/text_formats.cr

Class Method Summary

Class Method Detail

def self.email?(text : String) : Bool #

[email protected]: the strict shape. The last domain label is two or more letters.


[View source]
def self.hostname?(text : String) : Bool #

Labels of 1 to 63 letters, digits and hyphens, joined by dots, where each label begins and ends with a letter or digit.


[View source]
def self.ipv4?(text : String) : Bool #

Four dot-separated numbers from 0 to 255, each one to three digits. Leading zeros are accepted.


[View source]
def self.ipv6?(text : String) : Bool #

Eight groups of one to four hex digits, or up to seven with one ::, plus three special shapes: fe80: with a %zone, :: or ::ffff: or ::ffff:0: before an IPv4 address, and one to four groups and :: before an IPv4 address.


[View source]
def self.location_prefix?(text : String) : Bool #

True when text begins with a location: an optional http:// or https://, then host characters containing a dot followed by two or more letters or digits. Only the beginning is judged; String#url? accepts whatever follows it.


[View source]
def self.loose_email?(text : String) : Bool #

[email protected]: one @, no whitespace, and a dot with text on both sides somewhere after the @.


[View source]
def self.phone?(text : String) : Bool #

E.164: an optional +, a digit from 1 to 9, then 5 to 14 more digits.


[View source]
def self.time_of_day?(text : String) : Bool #

H:MM:SS or HH:MM:SS on a 24-hour clock.


[View source]
def self.uuid?(text : String) : Bool #

123e4567-e89b-12d3-a456-426614174000, in either case.


[View source]
def self.web_address?(text : String) : Bool #

The relaxed web address shape: an optional http:// or https://, then letters, digits, . and -, a dot, and two lowercase letters or dots. The rest may hold word characters, spaces, /, . and -.


[View source]