
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
A few extra validations for Ruby on Rails. Works with Ruby 2.1+ & Rails 4+.
We try to do the sane thing by not being too strict, when in doubt, we accept input as being valid. We never want to reject valid input as invalid.
For many formats doing a 100% foolproof check is not trivial, email addresses
are a famous example, but it also applies to other formats.
Regardless, you can never be sure itās what the user intended anyway. For
example, email validators will accept artin@ico.nl
as being āvalidā, even
though my email address is martin@lico.nl
.
The gem includes English and Dutch error messages. If you want to translate it
to another language then copy config/locales/en.yml
to your project.
Please send us your translations so we can add them!
Validate if a column is a valid date, and if itās before or after another date.
# Check if it looks like a valid date
validates :date_column, date: true
# We use a lambda for these checks because otherwise Date.today would be
# evaluated *only* on startup, and not every time we run the validations
# (you never want this).
validates :date_column, date: { after: -> { Date.today } }
validates :date_column, date: { after_or_equal_to: -> { Date.today } }
validates :date_column, date: { equal_to: -> { Date.today } }
validates :date_column, date: { before: -> { Date.today } }
validates :date_column, date: { before_or_equal_to: -> { Date.today } }
Check if the column enddate
is after the value of the column begindate
:
validates :begindate, date: true
validates :enddate, date: { after: :begindate }
Validate if a string looks like a valid domain. This should work with IDN.
This will accept lico.nl
, but rejects martin@lico.nl
:
validates :domain_column, domain: true
Set a minimum and maximum number of domain parts (aka. labels), this will accept
lico.nl
, but rejects lico
:
validates :domain_column, domain: { min_domain_parts: 2 }
Accept lico.nl
, but reject www.lico.nl
:
validates :domain_column, domain: { max_domain_parts: 2 }
Validate if a string looks like an email address. This should work with unicode addresses ([RFC 6531][rfc6531], [IDN][idn]).
Accepts martin@lico.nl
, but rejects martinlico.nl
or martin@lico
:
validates :email_column, email: true
Check if this is a valid IBAN account number. This uses the [iban-tools][iban-tools] gem.
validates :iban_column, iban: true
By default we set ānot a valid IBAN account numberā as the error message, but we can also set more detailed errors:
validates :iban_column, iban: { detailed_errors: true }
Note Since version 2.0, this gem no longer depends on iban-tools. If you
want IBAN validations, then you must add gem iban-tools
it to your Gemfile
manually.
Check if this is a valid phone number. This should work with most, if not all,
writing conventions. We consider a phone to be valid if it consists of numbers &
any amount of \-.()
characters. A country code at the start indicated with
+
is also accepted.
validates :phone_column, phone: true
Check if this is a valid postal code (or zip code for the states).
validates :postal_code_column, postal_code: { country: :nl }
# Country defaults to I18n.locale
validates :postal_code_column, postal_code: true
Currently implemented countries:
nl
- The NetherlandsCheck if this is a valid chamber of commerce identification number.
validates :commerce_number_column, commerce_number: { country: :nl }
Currently implemented countries:
nl
- The NetherlandsCheck if this is a valid VAT identification number
validates :vat_number_column, vat_number: { country: :nl }
Currently implemented countries:
nl
- The Netherlandsiban-tools
gem. If you want IBAN validations, then you
must add gem iban-tools
to your Gemfile manually (this is the only change,
but since it's incompatible I bumped the version to 2.0).commerce_number
validation.vat_number
validation.postal_code
validation will now raise an error if an invalid country
code is given.detailed_errors
option to get the more detailed errors.test@hello.world.example.com
).'invalid'.to_date
fails.phone
.date
without an argument.nil
.[idn]: http://en.wikipedia.org/wiki/Internationalized_domain_name). [rfc6531]: https://tools.ietf.org/html/rfc6531 [iban-tools]: https://github.com/iulianu/iban-tools
FAQs
Unknown package
We found that rails_validations demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.Ā It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.