user2911232
user2911232

Reputation:

Checking user's input and disallowing certain words

I have created a text input in which the user can input a website. However I want to disallow specific domains.

At first I want to be able to check if the input(domain, e.g. google.com) matches a specific word (e.g. google) - (I will later create a domains' blacklist).

In the controller (Rails) I want to check the input first before saving the object.

Any clue how can I check the input for a specific word?

Upvotes: 0

Views: 43

Answers (2)

Vijay Singh
Vijay Singh

Reputation: 23

You can try this

URI("http://www.google.com/").host =~ /google/

Here you can iterate through you blocked list of domains and can check above condition for each blocked domain.

Upvotes: 0

eXa
eXa

Reputation: 648

You could do that in regexp but there is a gem that is compliant to several rfc that would suit you better: https://github.com/sporkmonger/addressable#example-usage

Upvotes: 1

Related Questions