Re: Create a NSURL as a way to validate urls - not working
Re: Create a NSURL as a way to validate urls - not working
- Subject: Re: Create a NSURL as a way to validate urls - not working
- From: Jens Alfke <email@hidden>
- Date: Mon, 02 Mar 2015 18:51:50 -0800
> On Mar 2, 2015, at 4:52 PM, Keary Suska <email@hidden> wrote:
>
> That depends on what you mean by "validate." If you simply mean checking whether it well-formed, you can do that easily with a regular expression match, such as (written in email):
> ^http://(?:[a-z0-9-]+\.){1,}[a-z]{2,4}
It’s really much better to ask the system frameworks to do this kind of checking/parsing, since they are more likely than you are to know all the nuances of the RFCs. For instance, your regex above won’t work with international domain names, or capitalized forms of domain names, or top-level domains longer than 4 characters, or single-component domains like “foo”...
(I’m not saying this to pick on you, just warning people who might come across this thread in a web-search and copy and paste your regex. I’m sure it would also take me a while to write a regex that could reliably match domain names, assuming I even decided to try; that’s part of my point.)
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden