Skip to content

Instantly share code, notes, and snippets.

@DerKnerd
Created May 2, 2014 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DerKnerd/427c9a1553ac6247232e to your computer and use it in GitHub Desktop.
Save DerKnerd/427c9a1553ac6247232e to your computer and use it in GitHub Desktop.
CREATE FUNCTION [dbo].[IsValidURL] (@Url VARCHAR(200))
RETURNS INT
AS
BEGIN
IF CHARINDEX('https://', @url) <> 1 AND CHARINDEX('http://', @url) <> 1
BEGIN
RETURN 0; -- Not a valid
END
-- Get rid of the http:// stuff
SET @Url = REPLACE(@URL, 'https://', '');
-- Get rid of slashes
SET @Url = REPLACE(@URL, '/', '');
-- Now we need to check that we only have digits or numbers
IF (@Url LIKE '%[^a-z0-9]%.%[^a-z0-9]%.%[^a-z0-9]%')
BEGIN
RETURN 0;
END
-- It is a valid URL
RETURN 1;
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment