Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: None  |  size: 0.33 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Regex accepting names and numbers only
  2. var someString = "a string to test";
  3.  
  4. var namePattern = /[^A-Za-zd.'-]/;
  5.  
  6. if (namePattern.test(someString)) {
  7.    // contained invalid characters, do something
  8. }
  9.  
  10. // Or you can say /[^A-Za-zd.'-]/.test(someString) - no need to assign
  11. // the regex to a variable if you're not using reusing it.