Click here to Skip to main content
14,639,649 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello,

Can any one please provide me a solution to add all special characters into array.

For eg:

var description='~Special & Characters è *';

I need the below array
var specialCharacters= ["~", "&", "è",'*'];


What I have tried:

Below is the way i implemented in C# :

string entityName ="abc def & * ()@";		   
		    entityName=entityName.ToStr().Replace(" ", "");
            var allowablespecialCharacters = @"#$%^*";
            string patterns = @"[^A-Za-z0-9" + specialCharacters + "]";
            var b = Regex.Matches(entityName, patterns, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled);
            return b.Count > 0 ? true : false;


The same thing i need in Client Side.
Posted
Updated 7-Mar-18 4:11am
v3
Comments
Patrice T 7-Mar-18 2:00am
   
Do you provide money to the one doing your work?
Or do you ask someone to work for free?
suman palla 7-Mar-18 4:31am
   
If you know solution please provide. Else Ignore
CHill60 7-Mar-18 4:31am
   
The "What I have tried:" section is there for you to put the code that you have tried. If you do that then we will be able to help you work out what is wrong with it.
This is a Quick Answers forum not a code-writing service.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Although it's always easier to just give you the answer, we in CP prefer the harder way because that is the real way to help you.
First, replace non-special characters in the string with empty string using
JavaScript RegExp Reference[^] and JavaScript String replace() Method[^], then make them into an array using JavaScript String split() Method[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100