0

I am curious if there's a snippet in PHP/codeigniter/javascript/jquery for input that accept facebook/youtube link and validate that they are real link from them? I dont want to happen that the user inputs a malicious link in my normal input tag.

If there are no snippet available. What's the best but simple validation I can have in my inputs?

Drixson Oseña
  • 3,631
  • 3
  • 23
  • 36

1 Answers1

0

I think something in this trend would be the easyest option.

function validator( $url ){

    if( substr($url,0,18) == "http://youtube.com" || 
        substr($url,0,19) == "https://youtube.com" ||
        substr($url,0,22) == "http://www.youtube.com" ||   
        substr($url,0,21) == "https://www.youtube.com"
      ){
        $source = "youtube";
    }

    if( true == false ){    //  You can do this yourself
        $source=  "facebook";
    }

    if( !isset( $source ) ){
        return false;
    }
    else{
        return $source;
    }
}

var_dump( validator( "http://www.youtube.com/watch?v=dsfsf" ) );
var_dump( validator( "http://www.youtube.fake.com/watch?v=dsfsf" ) );
Frank Houweling
  • 595
  • 5
  • 14
  • Thank you for sharing your answer. I guess I will be using regex the answer can be found [here](http://stackoverflow.com/questions/2964678/jquery-youtube-url-validation-with-regex) – Drixson Oseña Aug 13 '13 at 01:35