2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

Restrict special characters using Javascript

I have a small requirement where I want to validate some text with special characters whether the text contain any special character or not.

If its contain any of the special character except alphanumeric then I need to define the proper action accordingly.

Please Suggest!


userimage

And here is the code snippet for you,


    var regExpression = /[`~!@#$%^&*()_|+-=?;:'",.<>{}[]/]/gi; // don't use any additional double quote here
    var isContainSplChar = regExpression.test(searchedText);
    if (isContainSplChar ) {
        
//my action should define here
        return false;
    }

Answer is