How to change a input field to be URL friendly

Hi,
I want to include one of the input field’s data in the URL of dynamic page… so i want to save it to my collection in the URL friendly format. In other words i am not expecting a complete URL from user but part of URL for my dynamic page. Right now i am looking for any unsafe character and replacing it with a safe one(encoding). Which is not effective way of doing it.

It should be similar to what Wix does when creating slug field.

Is there a validation that i can put on the input field or if you have a code that i can put in submit click please let me know. Thanks!

Have you figured this out? I am looking to do the same.