I just only want to check if that link is Google Maps link
For example :
var urls =[
/// correct urls
"https://www.google.com/maps",
"https://www.google.fr/maps",
"https://google.fr/maps",
"http://google.fr/maps",
"https://www.google.de/maps",
"https://www.google.com/maps?ll=37.0625,-95.677068&spn=45.197878,93.076172&t=h&z=4",
"https://www.google.de/maps?ll=37.0625,-95.677068&spn=45.197878,93.076172&t=h&z=4",
"https://www.google.com/maps?ll=37.0625,-95.677068&spn=45.197878,93.076172&t=h&z=4&layer=t&lci=com.panoramio.all,com.google.webcams,weather",
"https://www.google.com/maps?ll=37.370157,0.615234&spn=45.047033,93.076172&t=m&z=4&layer=t",
"https://www.google.com/maps?ll=37.0625,-95.677068&spn=45.197878,93.076172&t=h&z=4",
"https://www.google.de/maps?ll=37.0625,-95.677068&spn=45.197878,93.076172&t=h&z=4",
"https://www.google.com/maps?ll=37.0625,-95.677068&spn=45.197878,93.076172&t=h&z=4&layer=t&lci=com.panoramio.all,com.google.webcams,weather",
"https://www.google.com/maps?ll=37.370157,0.615234&spn=45.047033,93.076172&t=m&z=4&layer=t",
/// error urls
"https://www.google.com/",
"https://zzz.google.com/maps",
"https://www.google.com/+",
"httpsxyz://www.google.com/maps",
"http://www.anotherdomain.com/+"
];
I'm so bad about Regex and tried to use JavaScript Regex Generator but its still hard for me.
I got only ..
Reg = /^http\:\/\/|https\:\/\/|www\.google$/;
and its fail ! :(
But I made a live test for you all : http://jsbin.com/onuyux/1/edit?javascript,live
Edited : 2
After I got help from @joel harkes
& @dan1111
so i got regex
/^https?\:\/\/(www\.)?google\.[a-z]+\/maps\b/
This is regex for only google.{TLD}/maps
so what about maps.google.{TLD} ?
I just want to validate Google Maps URLs and urls from this way (look at the picture)
If possible I want to validate if address or long-lat is set (using li
or q
parameter check ?) (not only "maps.google.com" for example..)
Updated list + code :
/// correct urls
"https://www.google.com/maps?ll=37.0625,-95.677068&spn=45.197878,93.076172&t=h&z=4",
"https://www.google.de/maps?ll=37.0625,-95.677068&spn=45.197878,93.076172&t=h&z=4",
"https://www.google.com/maps?ll=37.0625,-95.677068&spn=45.197878,93.076172&t=h&z=4&layer=t&lci=com.panoramio.all,com.google.webcams,weather",
"https://www.google.com/maps?ll=37.370157,0.615234&spn=45.047033,93.076172&t=m&z=4&layer=t",
"https://maps.google.com/maps?q=New+York,+NY,+USA&hl=no&sll=19.808054,-63.720703&sspn=54.337928,93.076172&oq=n&hnear=New+York&t=m&z=10",
"https://www.google.com/maps?q=New+York,+New+York,+USA&hl=no&ll=40.683762,-73.925629&spn=0.708146,1.454315&sll=41.47566,-72.026367&sspn=11.190693,23.269043&oq=new&hnear=New+York&t=m&z=10",
/// error urls
"https://www.google.com/",
"https://zzz.google.com/maps",
"https://www.google.com/+",
"httpsxyz://www.google.com/maps",
"http://www.anotherdomain.com/+",
"http://maps.google.com/",
"http://google.com/maps",
"http://google.de/maps",
"?q=New+York,+New+York,+USA&hl=no&ll=40.683762,-73.925629&spn=0.708146,1.454315&sll=41.47566,-72.026367&sspn=11.190693,23.269043&oq=new&hnear=New+York&t=m&z=10",
"&sll=41.47566,-72.026367&sspn=11.190693,23.269043&oq=new&hnear=New+York&t=m&z=10"
Live test : http://jsbin.com/onuyux/25/edit?javascript,live
(www\.|maps\.)
which would fix it for that one line, but fail if the url is "maps.google.com/?q=" (which is valid if everything after the question mark matches your other conditions.). If you have 'maps.google', you don't need '/maps' at the end, which is where back-referencing would come in to play in a language other than JS. If you have '(www\.|maps\.)' and then make '/maps' conditional as well, it would be too flexible - thus why you need to compare against two regex in order to match all possible urls. – Amaranthinegoogle
also – Stowers(maps\.)?
instead of 'www.', and on that one make\/(maps)?
after the {TLD} – Amaranthinegoogle.co.uk
. – Andalusia