iPhone SDK: Check validity of URLs with NSURL not working?

前端 未结 5 2172
心在旅途
心在旅途 2020-12-12 03:52

I\'m trying to check if a given URL is valid and i\'m doing it like this:

- (BOOL)urlIsValid:(NSString *)address {
    NSURL *testURL = [NSURL URLWithString:         


        
5条回答
  •  长情又很酷
    2020-12-12 04:24

    I think you may be confused regarding the definition of "malformed". Anything conforming to RFC 2396 is considered valid; in practice, it seems NSURL will also accept [ and ] despite their not being allowed by the RFC.

    That means pretty much any string of printable ASCII characters besides space, ", % when not followed by two hex digits, <, >, \, ^, `, {, |, and } will be considered "valid", although it may not be absolute or generally useful. Strings containing multiple # may also be rejected.

提交回复
热议问题