Forum: Ruby on Rails Validating a legal subdomain

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
(Guest)
on 2008-12-11 18:06
(Received via mailing list)
I have a Rails app that uses subdomains as account keys. Users name
their own subdomains. How can I validate those subdomains as legal?
Peter De Berdt (Guest)
on 2008-12-12 10:33
(Received via mailing list)
On 11 Dec 2008, at 17:06, removed_email_address@domain.invalid wrote:

> I have a Rails app that uses subdomains as account keys. Users name
> their own subdomains. How can I validate those subdomains as legal?

Just like you would verify a user login. The subdomain then becomes
part of the login procedure. You store it in a table and you
"authenticate" the domain in a before_filter.


Best regards

Peter De Berdt
scottmotte (Guest)
on 2009-01-09 03:11
(Received via mailing list)
I think what Jeff meant is how to validate the subdomain as a normal
combination of letters and integers without a bunch of strange keys.
He's not talking about authentication, he's talking about validation.

I'll post here if I get this going Jeff. I'm also working on a way. It
looks like it will have to be a regular expression.

On Dec 12 2008, 12:33 am, Peter De Berdt <removed_email_address@domain.invalid>
Jeff (Guest)
on 2009-01-09 05:41
(Received via mailing list)
I eventually settled on a regex that permits only letters, numbers and
hyphens. Close enough for my needs:

  validates_format_of     :subdomain,
                          :with => /^[a-zA-Z0-9\-]*?$/,
                          :message => 'accepts only letters, numbers
and hyphens'

Hope that's helpful!

Jeff
Bobnation (Guest)
on 2009-01-09 06:16
(Received via mailing list)
That is pretty much what I was going to recommend.
scottmotte (Guest)
on 2009-01-09 06:43
(Received via mailing list)
Thanks Jeff. =)
This topic is locked and can not be replied to.