lundi 27 juin 2016

Url validation rails

In my model I have added the following code for validation of a URL a user can enter:

validates :website, presence: true
validates :website, format: { with: URI.regexp }, if: 'website.present?'

I have written a test with the an invalid url:

http://example,nl

When I run the test, the validation says this is a valid input. I have tried it in the program it self and this is an accepted URI. Is there a way to set the URI.regex so this is an invalid URL?

Aucun commentaire:

Enregistrer un commentaire