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

'hasOwnProperty' in javascript -

python - ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'> -

java - How to provide dependency injections in Eclipse RCP 3.x? -