문제

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.

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top