I am trying to validate that the link that I am entering into a form is a valid Google Earth link however, its accepting all link apart from google earth link; here is the code for my js script that I am trying to do this with.
validate: function() {
var inputFields = $('input[type=text]');
var notAvailable = $('#op_not_available');
var GoogleEarthUrl = $('#op_gooogle_earth_link').val().trim();
var twitterUrl = $('#op_twitter_url').val().trim();
var urlRegex = /^(ht|f)tps?:\/\/[a-z0-9-\.]+\.[a-z]{2,4}\/?([^\s<>\#%"\,\{\}\\|\\\^\[\]`]+)?$/;
var GoogleEarthRegex = /google.com/;
var twitterRegex = /twitter.com/;
if (!notAvailable.prop("checked")) {
$("#not_available").val('off');
for (var i = 0; i < inputFields.length; i++) {
if (!$(inputFields[i]).val().trim().length) {
return 'Please enter all fields';
}
}
if ((GoogleEarthUrl !== '-') && !(urlRegex.test(GoogleEarthUrl) && GoogleEarthRegex.test(GoogleEarthUrl))) {
return 'Please enter a valid Google Earth URL';
}
if ((twitterUrl !== '-') && !(urlRegex.test(twitterUrl) && twitterRegex.test(twitterUrl))) {
return 'Please enter a valid Twitter Url';
}
}else{
$("#not_available").val('on');
}
return;
}
};