0

In my app, I can have web URL starting with "https://" or "http://" or URL with custom scheme starting with "custom://" or "testing://".

I tried using URLUtil.isValidUrl(), but this returns true only if URL starts with http or https.

How can I validate the URL with custom scheme in android?

1 Answer 1

1

If i understand right, you just need to validate if the syntaxe is right, right ?

I did an sample here to validate URLs using Regex

val regex = "([A-Za-z]*:\\/\\/)?\\S*".toRegex()

fun isValidUrl(url: String): Boolean {
    return regex.containsMatchIn(url)
}
Sign up to request clarification or add additional context in comments.

5 Comments

isValidURL checks for all the other URL's mentioned. I looked at the implementation of isValidURL.
friendly tip: link-only answers are downvoted and not seen as answers. consider quoting the relevant parts from the links or adding this as a comment instead
@Gorio - Will try this out.
@Gorio - Unfortunately this returns true for invalid URL's too. For example if my URL is "test:^/something?a={123}&b={xyz}". This comes out to be a valid URL.
Sure. Just adjust the regex to accept only yours URLs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.