Skip to content

is_valid_url? #64

@ndrean

Description

@ndrean

I used this a few times:

def is_valid_url?(string) do
  [:scheme, :host, :port]
  |> Enum.map(&Map.get(URI.parse(string), &1))
  |> Enum.all?()
end
test "is_valid_url?/1" do
  assert is_valid_url?("http://www.google.com") == true
  assert is_valid_url?("http//google.com") == false
  assert s_valid_url?("ftp://google.com") == true
  assert is_valid_url?("https://google.com/api&url=ok") == true
  assert is_valid_url?("http://localhost:3000") == true
  assert is_valid_url?("https://localhost") == true
  assert is_valid_url?("htt:/google") == false
  assert is_valid_url?("www.google.com") == false
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussShare your constructive thoughts on how to make progress with this issueenhancementNew feature or requestpriority-2Second highest priority, should be worked on as soon as the Priority-1 issues are finishedquestionFurther information is requestedtechnicalA technical issue that requires understanding of the code, infrastructure or dependencies

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions