I want the regular expression to validate the URL with below condition,
- It should start with http or https
- It should end with the valid domain.
Ex: .com or .in but after the . can have any string. Specially, check whether the
.
is there and there is a string following the.
.
Valid URL: http://www.cnn.com
Invalid URLS:
htt://www.yahoo.com
http://www.yahoo.
http://www.yahoo
I have compose the regular expression as below.
/^(http|https):\/\/[-a-zA-Z0-9+&@#/%?=~_|!:,;]+([\-\.]{1}[-a-zA-Z0-9+&@#/%?=~_|]+)*\.[a-zA-Z]{2,5}(:[0-9]{1,5})?(\/.*)?$/
It worked fine for most of the scenarios.
But if I enter http://www.yahoo
didn't validate correctly, but If I enter http://www.google
it throws the validation error.
Can anybody please help me to resolve this issue?