Euler G. Posted March 11, 2011 Share Posted March 11, 2011 Greetings,I'm trying to validate a URL entry using RegExp. I've been using the pattern "\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]" successfully in other languages but it seems to not work in AutoIt3. This pattern is meant to match any valid URL, but in my particular case I only need to check for http/https. Below is a snippet I'm using:If Not StringRegExp(GUICtrlRead($inp_Url), "https?://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]") Or GUICtrlRead($inp_Url) = "" Then MsgBox(16, "Invalid URL error", "URL " & GUICtrlRead($inp_Url) & @LF & "either blank or invalid." & @LF & @LF & "Error: " & @error, 10) ThenNo matter what I inform, StringRegExp() always returns 0 (zero). What am I missing? TIA. Best, Euler Link to comment Share on other sites More sharing options...
zackrspv Posted March 19, 2011 Share Posted March 19, 2011 Greetings, I'm trying to validate a URL entry using RegExp. I've been using the pattern "\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]" successfully in other languages but it seems to not work in AutoIt3. This pattern is meant to match any valid URL, but in my particular case I only need to check for http/https. Below is a snippet I'm using: If Not StringRegExp(GUICtrlRead($inp_Url), "https?://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]") Or GUICtrlRead($inp_Url) = "" Then MsgBox(16, "Invalid URL error", "URL " & GUICtrlRead($inp_Url) & @LF & "either blank or invalid." & @LF & @LF & "Error: " & @error, 10) Then No matter what I inform, StringRegExp() always returns 0 (zero). What am I missing? TIA. Whenever i need to validate a URL entry from a client, I really just do a basic url stat test, and sure there's data after it: local $URL_Heads = "http|https|file|ftp|gopher|rtsp" $URL = StringRegExp(GUICtrlRead($inp_Url), "["&$URL_Heads&"]\://(.*?)",3,1) if NOT IsArray($URL) then MsgBox(16, "Invalid URL error", "URL " & GUICtrlRead($inp_Url) & @LF & "either blank or invalid." & @LF & @LF & "Error: " & @error, 10) Else MsgBox(0, "Good", "URL is valid: "&GUICtrlRead($inp_Url)) EndIf If it passes the heads test, then i do a simple connect test to ensure the URL is valid. I do check for DNS providers as well, as many people who use Google DNS, OpenDNS, FreeDNS, etc, will be given an ip address regardless of what URL they type in. (This check is simple, just make up a random URL, ping it, record the IP i nthe script as the DNS related IP address, then ping the above URL to obtain the address, compare, and if the same, then the URL is invalid). But, i have found, with security standards changing, that pinging a web address isn't really effective to see if it's valid. instead, creating a connection to it (web based), or TCP based for the others, is necessary. There are many functions that can do this, most notably the _IE* ones, and the TCPConnect* ones. My general rule of thumb is: Verify Text inputVerify endpoint (with either IE or TCP based on head) Doesn't even need to be this complex, honestly. Just verify the heads, and go, and do some error handling on your connect strings. -_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë. Link to comment Share on other sites More sharing options...
GEOSoft Posted March 19, 2011 Share Posted March 19, 2011 @zackrspv Have you been paying any attention to the forums at all? This is a duplicate thread and it was answered in the other one. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
zackrspv Posted March 19, 2011 Share Posted March 19, 2011 have i been paying attention to the forums at all? no, not really. Do i really care if i answer a dup post? No, not really. information is information. i'm allowed to reply to whatever thread I want. I didn't cuss anyone out, i didn't state anything that's untrue, i didn't do anything wrong. So yeah, whatever. -_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë. Link to comment Share on other sites More sharing options...
GEOSoft Posted March 19, 2011 Share Posted March 19, 2011 have it your way then but best you lose the attitude along the way. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
zackrspv Posted March 19, 2011 Share Posted March 19, 2011 have it your way then but best you lose the attitude along the way.Nah I'm allowed to have whatever attitude i wish Just like anyone else on this forum, i'm allowed to post whenever, and however I wish. As long as i dont break the terms of service (which i havn't flamed, or done anything wrong therein), i'm fine But, anywho. i'm sure you'll end up replying to this with some retort or something, but i have better things to do than read those. So, have fun -_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 20, 2011 Moderators Share Posted March 20, 2011 (edited) Edit: Search for IsValidURL Edit2: The above post was for "zacks" benefit. I'm closing this duplicate topic. Edited March 20, 2011 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Recommended Posts