I have this javascript function that block special characters…
function validaTexto(texto) { !(/^[A-zÑñ0-9]*$/i).test(texto.value) ? texto.value = texto.value.replace(/[^A-zÑñ0-9]/ig, '') : null; }
The problem is that this function doesn’t allow me to type blank spaces… how can I customize this function to allow me some other things, such as blank spaces, ‘,’ , ‘.’ , ‘;’ and so on?
Thanks!!
change the regex to this:
also, the function is quite redundant in that it checks the string twice, basically saying ‘Does the string contain any of these characters? Yes? Ok, so search the string for these same characters and remove them. Just change it to this: