nerdnews icon indicating copy to clipboard operation
nerdnews copied to clipboard

[insisting] on URL validation check

Open bijanebrahimi opened this issue 11 years ago • 1 comments

as previously mentioned here http://bit.ly/Y3hJD8, it is necessary to have URL existence validation. if you think it will cause some sort of annoying delay, you can simply put it in view (and run it on client side) using javascript.

IMPORTANT: when the news will be briefly available by the supplied referenced link, it is vital to check if it's a valid one before sending stories.

a snippet-code/guide for developers:

$('story[source]').on('blur', function({
   news_resource_url = $(this).attr('value');
   //~ you can first check for the URL validation Regex Here
   if(url_validation_check(news_resource_url)){
      //~ and when if it has a Valid URL schema, check for url HTTP response
      $.ajax({ type: 'head', url: news_resource_url,
         success: function() {
            // URL exists
            $('story[source]').parent().parent().removeClass('error');
         }, error: function() {
           // page does not exist
           $('story[source]').parent().parent().addClass('error');
         }
     });
   }else{
      //~ url is not valid, do something
      $('story[source]').parent().parent().addClass('error');
   }
});

function url_validation_check(url){ 
   # this function is a slightly modification of this one: http://bit.ly/14IJ4h0
   return /((https?|ftp):\/\/(\w+:{0,1}\w*@)?(\S+)|)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!-\/]))?/.test(url); 
} 

bijanebrahimi avatar Mar 10 '13 08:03 bijanebrahimi