Q:

Regular expression: a string (a-z, A-Z, 0-9, can include '\', '/' and white sapce)

I want a regex that has a string  (a-z, A-Z, 0-9, can include '\', '/' and white sapces)
I tried it like this:  
if (/[\s\\\/A-Za-z0-9]$/.test(Yourval)), 

but it doesn't work well, can somebody help me? thanks!

A:

This should work:
if (/^[a-zA-Z0-9\s\\\/]+$/.test('Something with / and \\ 0 9')) { 
  alert('Good news everyone!'); 
}

... as you need two anchors here (both for the start and the end of the string), and + quantifier to test for more than a single character. In fact, this can be rewritten just as...
if (/[^a-zA-Z0-9\s\\\/]/.test('Something with / and \\ 0 9')) { 
  alert('Crazy gibberish!'); 
}

... so we test for bad characters instead of trying to cover the string with only good ones. )

