Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to validate a url that is with or without http. i tried ^http(s{0,1})://[a-zA-Z0-9_/\-\.]+\.([A-Za-z/]{2,5})[a-zA-Z0-9_/\&\?\=\-\.\~\%]*

But this is matches http://google.com but not www.google.com. i want a regex that matches www.google.com too.

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
191 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try starting your regex with ^(https?://)? instead of ^http(s{0,1})://


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...