javascript - Regex URL validation for angularjs -


i'm trying create validation url accept following cases http or https or without, www or without, subpages or without

http://website.com https://website.com http://website.com/ http://www.website.com website.com http://website.com/page/id/sdf 

i tried following, did not cover cases above

$scope.urlpattern = '^(([a-z]+[.])?[a-z0-9-]+([.][a-z]{1,4}){1,2}(/.*[?].*)?$' $scope.urlpattern = '^((https?|ftp)://)?([a-z]+[.])?[a-z0-9-]+([.][a-z]{1,4}){1,2}(/.*[?].*)?$' 

i not have permission add comment, editing answer only. below link has type of url validation, hope you:

all type url validation link

if want validate url, don't need concern 'www' condition (since included in other condition)

something simple can done this:

'^(https?:\/\/)*[a-z0-9-]+(\.[a-z0-9-]+)+(\/[a-z0-9-]+)*\/?$'

jsfiddle: https://jsfiddle.net/q0d69jq3/2/


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -