find special charated and Replace with '- ' using jqery

Mohammad Qasim 576 Reputation points
2020-08-05T12:22:12.37+00:00

Hi,

having textbox on page where user can input document name using special character like

1) abc%test.
2) abc&test
3) abctest.
4) abc/test
5) abc+test
6) abc(test)
7) abc_test

Solution Required:

I want to change all these special charater with '-' . so it will be like below ( after replace ).
abc-test not abc%test

if any special character not get changed so it should prompt like " invalid character "

SharePoint Server
SharePoint Server
A family of Microsoft on-premises document management and storage systems.
2,346 questions
{count} votes

Accepted answer
  1. Jerryzy 10,571 Reputation points
    2020-08-06T01:55:56.477+00:00

    Hi @Mohammad Qasim ,

    You can use JavaScript Regex to replace special charater with "-".

    The code in attachment is a sample code for your reference:

    15948-code.txt

    Reference:

    Remove all special characters with RegExp


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.