One minute
Better way to write URL Validation 🔗
Use URI::regexp(%w(http https))
in your Ruby on Rails model, to increase readability of website(URL) validation.
Code snippet 📌
# website URL validation
validates :website, format: { with: /((?:(http|https)?\:\/\/|www\.)(?:[-a-z0-9]+\.)*[-a-z0-9]+.*)/i }
# can be write as
validates :website, format: { with: URI::regexp(%w(http https)) }
Read other posts
comments powered by Disqus