Remove special characters from string using jquery [closed]
-
29-01-2021 - |
Pergunta
How to remove special characters from string. If user provided any special character from the below set of characters that should be removed:
| \ " ' / [ ] : < > + = , ; ? * @
I tried regex. But it is not replacing. Please find below code:
var subSiteTitleval=$("input[title='Subsite Title Required Field']").val();
subSiteTitleval= subSiteTitleval.replace(/[@><,:;][+=?"'*/|]/g, ' ');
$("input[title='Subsite Title Required Field']").val(subSiteTitleval);
});
Kindly respond.
Solução
Can you try this?
var subSiteTitleval=$("input[title='Subsite Title Required Field']").val();
subSiteTitleval= subSiteTitleval.replace(/[^a-zA-Z0-9-. ]/g, ' ');
$("input[title='Subsite Title Required Field']").val(subSiteTitleval); });
If you don't want to remove some of the special characters, just add inside regex like this
/[^a-zA-Z0-9-. &]/g
You can refer to this
Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange