Only allow printable ASCII (UTF8) characters
<form >
<input type="text" id="CreatedByText" />
</form>
<script>
document.getElementById('CreatedByText').addEventListener('input', function ()
{
//Keep printable ASCII only (space to tilde, 0x20–0x7E):
let el = document.getElementById('CreatedByText');
el.value = el.value.replace(/[^\u0020-\u007E]/g, '');
});
</script>
Validating in PHP
if(!mb_check_encoding($_POST['MyField'] ?? '', 'UTF-8')) {
// reject or convert
}
