Re: [ruby-83] Got tired of regexes for domain validation, so made this

From: Steve E.
Sent on: Thursday, October 4, 2012 5:31 PM
On Oct 4, 2012, at 5:02 PM, Frank Rietta <[address removed]> wrote:

Is this the best way to do this though?  What have others done for validating domain names?

I think if I ever had to, I might check to confirm the existence of a mid-string period and the absence of colons or slashes; but I'd do that in Javascript, and only to provide fast feedback in case the user misunderstood what was being asked for.

I definitely wouldn't work hard at it though. Matching formal RFC specs doesn't tell you anything about whether the value will work.  True 'validation' will only happen when you try doing whatever you need to do with that domain name.  If you're supposed to access it and you succeed at getting data back, the name is valid.  If you're supposed to register it and you get an error that the name already exists, the name is invalid.

Because Rails makes simple validations so easy, a lot of Rails apps get bogged down in excessively validating things that don't have a cost.  In most cases it just doesn't matter if Madonna left the "last name" field blank, or if someone put spaces in their phone number.  Business can usually still get done. You only need to validate things that would cause the fundamental business requirement to fail.  The test for whether a domain name will 'work' depends on what the requirement is, but it almost certainly isn't counting characters.


Have Fun,
Steve Eley

Our Sponsors

  • Mandrill

    Sponsors food, meeting space, and other expenses.

  • Primedia

    hosts the coding group meetings

  • Big Nerd Ranch

    is sponsoring the group and organizes the monthly meetup!

  • ATDC

    provides space for meetings.

  • Emcien

    sponsors the Intermediate Ruby subgroup

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy