I am trying to build a homebrew web brower to get more proficient at Cocoa. I need a good way to validate whether the user has entered a valid URL. I have tried some regular expressions but NSString has some interesting quirks and doesn't like some of the back-quoting that most regular expressions I've seen use.
相关问题
- Date with SimpleDateFormat in Java
- UrlEncodeUnicode and browser navigation errors
- Improve converting string to readable urls
- Regex to match charset
- Regex subsequence matching
相关文章
- Angular Material Stepper causes mat-formfield to v
- Optimization techniques for backtracking regex imp
- Regex to check for new line
- Why doesn't Django enforce my unique_together
- Allow only 2 decimal points entry to a textbox usi
- Comparing speed of non-matching regexp
- Converting (u)int64_t to NSNumbers
- Regular expression to get URL in string swift with
You could start with the
+ (id)URLWithString:(NSString *)URLString
method ofNSURL
, which returnsnil
if the string is malformed.If you need further validation, you can use the
baseURL
,host
,parameterString
,path
, etc methods to give you particular components of the URL, which you can then evaluate in whatever way you see fit.I've found that it is possible to enter some URLs that seem to be OK but are rejected by the NSURL creation methods. So we have a method to escape the string first to make sure it's in a good format. Here is the meat of it: