Is there any way to accept a URL and change it's domain to `.com` ?

For example if a user were to submit `www.example.in`, I want to check if the URL is valid, and change that to `www.example.com`. I have built a regex checker that can check if the URL is valid, but I'm not entirely sure how to check if the given extension is valid, and then to change it to `.com`

EDIT : To be clear I am not actually going to these URL's. I am getting them submitted as user input in a form, and am simply storing them. These are functions I want to do to the URL before storing, that is all.

Edit 2 : An example to make this clearer -

```
$url = 'www.example.co.uk'
$newurl = function($url);
echo $newurl

```

which would yield the output

```
 www.example.com

```