Proper way to sanitize external urls to insert into database [JavaScript, PHP]

I am trying to implement a function that allows users to input any URL they would like to their home screen on my website.

Is there a proper way to sanitize URL links before inserting to a database?

Thank you in advance!