Module: Securial::Helpers::RegexHelper
Overview
Regular expression patterns and validation methods for common data types.
This module centralizes regex patterns used throughout Securial for validating user input. It provides both the raw regex patterns as constants and convenience methods for validation.
Constant Summary collapse
- EMAIL_REGEX =
RFC-compliant email address validation pattern.
Uses Ruby’s built-in URI::MailTo::EMAIL_REGEXP which follows RFC 3696 specifications for email address validation.
URI::MailTo::EMAIL_REGEXP
- USERNAME_REGEX =
Username validation pattern with specific formatting rules.
Enforces the following username requirements:
-
Must start with a letter (not a number)
-
Can contain letters, numbers, periods, and underscores
-
Cannot have consecutive periods or underscores
-
Must end with a letter or number
-
Minimum length of 2 characters
-
/\A(?![0-9])[a-zA-Z](?:[a-zA-Z0-9]|[._](?![._]))*[a-zA-Z0-9]\z/- PASSWORD_REGEX =
Password complexity validation pattern.
Enforces strong password requirements including:
-
At least one digit (0-9)
-
At least one lowercase letter (a-z)
-
At least one uppercase letter (A-Z)
-
At least one special character (non-alphanumeric)
-
Must start with a letter
-
%r{\A(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9])[a-zA-Z].*\z}
Instance Method Summary collapse
-
#valid_email?(email) ⇒ Boolean
Validates if an email address matches the RFC-compliant pattern.
-
#valid_password?(password) ⇒ Boolean
Validates if a password meets complexity requirements.
-
#valid_username?(username) ⇒ Boolean
Validates if a username follows the defined formatting rules.
Instance Method Details
#valid_email?(email) ⇒ Boolean
Validates if an email address matches the RFC-compliant pattern.
Uses the EMAIL_REGEX pattern to check if the provided email address follows proper email formatting standards.
89 90 91 |
# File 'lib/securial/helpers/regex_helper.rb', line 89 def valid_email?(email) email.match?(EMAIL_REGEX) end |
#valid_password?(password) ⇒ Boolean
Validates if a password meets complexity requirements.
Uses the PASSWORD_REGEX pattern to check if the provided password meets the application’s security standards.
135 136 137 |
# File 'lib/securial/helpers/regex_helper.rb', line 135 def valid_password?(password) password.match?(PASSWORD_REGEX) end |
#valid_username?(username) ⇒ Boolean
Validates if a username follows the defined formatting rules.
Uses the USERNAME_REGEX pattern to check if the provided username meets the application’s username requirements.
113 114 115 |
# File 'lib/securial/helpers/regex_helper.rb', line 113 def valid_username?(username) username.match?(USERNAME_REGEX) end |