0

I have the following set of symbols:

var a = '|\/~^:,;?!&%$@*+';

How can I check is the following string contains any of those symbols?

var b = 'avguybdf';
gespinha
  • 7,968
  • 16
  • 57
  • 91

4 Answers4

2

As suggested, regular expressions will work.

b.match(/[|\\/~^:,;?!&%$@*+]/);

EDIT: I originally used the method here https://stackoverflow.com/a/6969486/2044733 to escape the string but because of the grouping, only the backslash character needs to be escaped.

The "/" at the beginning and end of the string are the delimiters for regular expressions in javascript, and "[]" are used to group the characters. In case you're wondering how this works.

Community
  • 1
  • 1
bbill
  • 2,264
  • 1
  • 22
  • 28
0

Use RegEx

Check the how to use regex @ Javascript RegEx

Uday Shankar
  • 844
  • 7
  • 20
0

Use RegEx. You can use test() or exec(). Read more here: http://www.w3schools.com/jsref/jsref_obj_regexp.asp