addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgooglegroupshelp-with-circleimageimagesinstagramlinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

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

From: Lando
Sent on: Friday, October 5, 2012 1:21 AM
Problem with regex usage is that whenever something gets somewhat complicated a regex tends to become more and more complicated.  Take validating an email address, 514 characters.  It might be more efficient than other methods, or not as the case may be, but it is certainly too complicated for the human mind to comprehend the entire thing at once.  Far better to use some string processing and work through it that way.

That being said, your method of validating domain names has multiple issues, what is the purpose of the domain testing here?   Why are you testing for a valid domain name, or is it just being used to give a high level hit/miss response?  I'd throw a few comments in and tighten up the code a bit before I'd consider that code complete, email me directly and we can work through what you want to do and how to accomplish your goal.


On Thu, Oct 4, 2012 at 5:31 PM, Steve Eley <[address removed]> wrote:
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

Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Steve Eley ([address removed]) from The Atlanta Ruby Meetup Group.
To learn more about Steve Eley, visit his/her member profile

Our Sponsors

  • Mailchimp

    Sponsors food, meeting space, and other expenses.

  • Pardot

    Sponsors food, meeting space, and other expenses.

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