To check if a word is palindrome, you ignore the spaces which you don’t remove in your regex you need to remove the \s from your character set in order to find those spaces and remove them.
const regex=/[^\w\s]|_/g
Then, in case of clicking the button without entering any value, you checked for this case and used alert but after that you need to stop executing the function and exit. So you need to add return after your alert.
if (input.value === "") {
alert("Please input a value")
}
Lastly…
if (input.value.toLowerCase() === reversed(input.value))
Here, you are checking the original input.value which may contain spaces or punctuation which you need to clean your input before comparing it to the reversed one. Then use your cleanString function on input.value.
This will match any alpha-numeric characters including underscore _, but in your code you want to replace any character that is NOT alpha-numeric including underscore with an empty string "".
So you have to make the regex match underscores and any character that is not alpha-numeric.
You can view your original posted regex on the topic and see why i told you to remove only the \s and keep the rest, and compare it with the one here.
But your new one here can be used with one little modification, remove the negated character ^ from your character set and it will work. Cause that way it will match any non alpha-numeric character \W and also the underscore _ which you will then replace the match result with empty string in your code "".