wuwuxin 28 Posted April 18, 2021 In C#, there is a Uri.IsWellFormedUriString Does Delphi provide a similar utility? Share this post Link to post
Dave Novo 51 Posted April 18, 2021 You can use the built in Regex tools in delphi and use the Regex from the following link https://stackoverflow.com/questions/30847/regex-to-validate-uris maybe 3 lines of code... Share this post Link to post
wuwuxin 28 Posted April 18, 2021 3 hours ago, Dave Novo said: You can use the built in Regex tools in delphi and use the Regex from the following link https://stackoverflow.com/questions/30847/regex-to-validate-uris @Dave Novo Dave - many thanks for the heads up. Following your advice, I resorted to RegEx, using the following code, and it works well for me. I posted the code here, in case someone may have the same needs. Thanks again. procedure MyFunkyRegExProcedure; const sUrlRegEx: String = '^'#10 + '(# Scheme'#10 + ' [a-z][a-z0-9+\-.]*:'#10 + ' (# Authority & path'#10 + ' //'#10 + ' ([a-z0-9\-._~%!$&''()*+,;=]+@)? # User'#10 + ' ([a-z0-9\-._~%]+ # Named host'#10 + ' |\[[a-f0-9:.]+\] # IPv6 host'#10 + ' |\[v[a-f0-9][a-z0-9\-._~%!$&''()*+,;=:]+\]) # IPvFuture host'#10 + ' (:[0-9]+)? # Port'#10 + ' (/[a-z0-9\-._~%!$&''()*+,;=:@]+)*/? # Path'#10 + ' |# Path without authority'#10 + ' (/?[a-z0-9\-._~%!$&''()*+,;=:@]+(/[a-z0-9\-._~%!$&''()*+,;=:@]+)*/?)?'#10 + ' )'#10 + '|# Relative URL (no scheme or authority)'#10 + ' ([a-z0-9\-._~%!$&''()*+,;=@]+(/[a-z0-9\-._~%!$&''()*+,;=:@]+)*/? # Relative path'#10 + ' |(/[a-z0-9\-._~%!$&''()*+,;=:@]+)+/?) # Absolute path'#10 + ')'#10 + '# Query'#10 + '(\?[a-z0-9\-._~%!$&''()*+,;=:@/?]*)?'#10 + '# Fragment'#10 + '(\#[a-z0-9\-._~%!$&''()*+,;=:@/?]*)?'#10 + '$'; begin var LRegEx := TRegEx.Create(sUrlRegEx, [roIgnoreCase, roIgnorePatternSpace]); var LMatch := LRegEx.Match(FUrl); end; 2 Share this post Link to post
Dmitry Arefiev 101 Posted April 21, 2021 try var LURI := TURI.Create(AURI); Result := True; except Result := False; end; 1 2 Share this post Link to post
Anders Melander 1782 Posted April 21, 2021 On 4/19/2021 at 12:57 AM, wuwuxin said: var LRegEx := TRegEx.Create(sUrlRegEx, [roIgnoreCase, roIgnorePatternSpace]); var LMatch := LRegEx.Match(FUrl); Or the one-liner: TRegEx.IsMatch(FUrl, sUrlRegEx, [roIgnoreCase, roIgnorePatternSpace]) Share this post Link to post