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