1

Please do read full question before marking it duplicate.

I want to validate URL which can contain query string. I found some of the solutions. But It is not working for me. Examples of valid URLs for me are:
1)http://www.example.com/
2)www.example.com
3)example.com
4)http://www.exaple.com/test2/aa.aspx?id=2&sad=ss

I have used following expression:
1) ^((http|https)://)?([\w-]+\.)+[\w]+(/[\w- ./?]*)?$

But when I used this expression Query string were not allowed.

2) (http|ftp|https)://([\w+?\.\w+])+([a-zA-Z0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?
But in this http is required. If i enter URL like: google.com this expression says it is not valid.

Can anyone help me to validate this?
Thank you in advance.

Rahul Gokani
  • 1,688
  • 5
  • 25
  • 43

2 Answers2

2

Below expression worked for me. Please try this:

^((http|https|ftp|www):\/\/)?([a-zA-Z0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)(\.)([a-zA-Z0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]+)
WarLock
  • 58
  • 6
-1

Can you please try the below expression and let me know the result

((http|ftp|https):\//(www)\.{0,}){0,}\w*\.\w{3}((\/\w*){1,}\.\w*\?{1}(\w*\=\w*){0,}\&{0,}(\w*\=\w*){0,}){0,}
Kaustav Banerjee
  • 275
  • 1
  • 10