1

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.

closed as off-topic by Christoffer, Gaurravs, Karthik Jaganathan, MHeld, Waqas Sarwar MVP Nov 29 '18 at 17:39

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Programming questions not specific to SharePoint are off-topic here, but can be asked on Stack Overflow." – Christoffer, Gaurravs, Karthik Jaganathan, MHeld, Waqas Sarwar MVP
If this question can be reworded to fit the rules in the help center, please edit the question.

0

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.