I have this RegExp in JS and I am using .test()
method for validating the url:
new RegExp(/^((https|http):\/\/www\.)?(www\.)?[a-z0-9_-]+\.[a-z]+(\/)?(\/[a-z0-9]+(\.(php|html|asp|aspx))?)?$/i)
I want a RegExp that can validate this types of url (notice things like http and https):
https://www.page.com/about.php
https://www.page.com/about
https://www.page.com/
www.page.com
page.com
page-10.com
1234.com
This RegExp works when I try those url except when I try this url:
www.page
It takes that url as true, and I don't know why...
First part of my regexp says: the url could have https|http://www.
or www.
at the beginning or none of them.
/^((https|http):\/\/www\.)?(www\.)?
Second part says: after first part there will be letters, numbers, some simbols + a dot (here is where my error comes from I think. Why it doesn't recognize the dot?) + more letters, the result could be something like page-10.com
[a-z0-9_-]+\.[a-z]+
Third part is optional, it allows a slash and an extension like page.com /about.php:
(\/)?(\/[a-z0-9]+(\.(php|html|asp|aspx))?)?$
Question:
In the second part I expect a dot when I say: \.
, but it doesn't recognize it, how can I be explicit and ask for it?