AppleScript名:URLの妥当性チェック |
— Created 2015-09-06 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" –http://stackoverflow.com/questions/1471201/how-to-validate-an-url-on-the-iphone set aRes1 to validateURL("http://www.apple.com/jp") –> true set aRes2 to validateURL("http.s://www.gmail.com") –> false set aRes3 to validateURL("https:.//gmailcom") –> false set aRes4 to validateURL("https://gmail.me.") –> false set aRes5 to validateURL("https://www.gmail.me.com.com.com.com") –> true set aRes6 to validateURL("http:/./ww-w.wowone.com") –> false set aRes7 to validateURL("http://.www.wowone") –> false set aRes8 to validateURL("http://www.wow-one.com") –> true set aRes9 to validateURL("http://www.wow_one.com") –> true set aRes10 to validateURL("http://.") –> false set aRes11 to validateURL("http://") –> false set aRes12 to validateURL("http://k") –> false return {aRes2, aRes3, aRes4, aRes5, aRes6, aRes7, aRes8, aRes9, aRes10, aRes11, aRes12} –> {false, false, false, true, false, false, true, true, false, false, false} –URLの妥当性チェック on validateURL(anURL as text) –set regEx1 to current application’s NSString’s stringWithString:"(http|https)://((\\w)*|([0-9]*)|([-|_])*)+([\\.|/]((\\w)*|([0-9]*)|([-|_])*))+" set regEx1 to current application’s NSString’s stringWithString:"((https|http)://)((\\w|-)+)(([.]|[/])((\\w|-)+))+" set predicate1 to current application’s NSPredicate’s predicateWithFormat_("SELF MATCHES %@", regEx1) set aPredRes1 to (predicate1’s evaluateWithObject:anURL) as boolean return aPredRes1 end validateURL |
More from my site
(Visited 35 times, 1 visits today)