I have to inputs, one is for when you enter the a site name and the other one is only a readable input where the site name turns into the url. Like in the screenshot below:
So I have this:
const handleChange = (e) => {
setSiteInfoDataAction({
...siteInfoData,
siteName: e.target.value, // for the Site Name input
url: e.target.value.toLowerCase().replace(/\s/g, "-"), // for the URL input
});
e.preventDefault();
};
So the only validation i am doing is that every time there is a space, a hyphen is replacing the space. But I need to validate that the user is entering a valid name to recreate the URL. Get it? I need to regex to allow the user to enter only URL friendly characters.
Any ideas on how I can achieve that?
EDIT
You should notice that the regex should validate only the part after the slash /
. Just like in the input in the screenshot. So the regex won't validate any http/s or www. Just whatever is after the /
should be URL friendly.