3

I use this code to valid url

public static bool isUrl(string text) { Uri uriResult; return Uri.TryCreate(text, UriKind.Absolute, out uriResult) && uriResult.Scheme == Uri.UriSchemeHttp; } 

but this code, not working when i send parameters like google.com, www.google.com

it only work when i use http like http://google.com

i need a code for c#, like Patterns.WEB_URL.matcher(text).matches(); in android

1 Answer 1

2

I use this regex.

[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/=]*) 

Here's the regex in action with this question's url: enter image description here

So if a match is found you got yourself a URL. And if in the future you need to get parts of it it can do that for you too.

Sign up to request clarification or add additional context in comments.

1 Comment

Interesting in this regard: stackoverflow.com/questions/161738/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.