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 -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -

How to understand 2 main() functions after using uftrace to profile the C++ program? -