kwaigon
kwaigon

Reputation: 815

Rails: validation for top level domain only

I need some regex or maybe native Rails trick to check if user entered only domain (without "http", "https", "www" and so on. So, this one would be valid:

google.com.ua

And this would be invalid:

https://www.google.com.ua

Maybe, it can be simplified just to check if string contains only dots and take it like valid one, and if it contains any other characters - block it.

Tell me please what is better to use for such case and what would be regex for it or another decision.

Thanks.

Upvotes: 2

Views: 966

Answers (1)

vks
vks

Reputation: 67988

^(?!www\.)[a-zA-Z0-9.-]+$

Try this.See demo.

https://regex101.com/r/wZ0iA3/5

Upvotes: 3

Related Questions