Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Inspiration: https://www.purebasic.fr/english/vie...p?f=12&t=44359
- ; Validates URLS
- ; --------------
- ; Must include a scheme such as http:// or ftp://
- ; Support for port numbers and numeric IPs
- ;
- ; Returns #True or #False
- ; -----------------------------------------------
- ; Store this string in a constant
- #URL_PATTERN = "^([a-z0-9]+://)(([0-9a-z_!~*'().&=+$%-]+:)?[0-9a-z_!~*'().&=+$%-]+@)?(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-z_!~*'()-]+\.)*([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\.[a-z]{2,6})(:[0-9]{1,4})?((/?)|(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$"
- ; A DLL Procedure, which returns an int (1 or 0)
- ProcedureDLL.i ValidURL(url.s)
- ; False by default
- Protected result = #False
- ; Create a regular expression, #PB_Any means that the new handle will be returned instead of predetermined
- Protected regex = CreateRegularExpression(#PB_Any, #URL_PATTERN)
- If(regex) ; check to make sure the regex was successfully created
- ; Match the URL and store the result as a 1 or 0
- result = Bool(MatchRegularExpression(regex, url)) ; Bool() converts the zero or non-zero result of Match to 1 or 0 (true or false)
- ; Free the resources used by the regex, we're done
- FreeRegularExpression(regex)
- EndIf
- ; Return the result
- ProcedureReturn result
- EndProcedure
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement