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

Untitled

By: a guest on Jul 1st, 2012  |  syntax: None  |  size: 0.86 KB  |  hits: 15  |  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. YA Javascript Regex Question
  2. A-z 0-9 - _ ' & .
  3.        
  4. /^[A-z0-9_]+(-)+$/i
  5.        
  6. /^[a-zA-Z0-9&_.-']+$/
  7.        
  8. <script type="text/javascript">
  9.     //A-z 0-9 - _ ' & .
  10.     //valid
  11.     var test_string = "This'Is'-Val1d&_.";
  12.     if (test_string.match(/^[a-zA-Z0-9&_.-']+$/)){
  13.         alert("first test matched");
  14.     }else{
  15.         alert("first test did not match");
  16.     }
  17.  
  18.     //invalid - whitespace not allowed
  19.     test_string = "This IsNot- Va'l1d & _ .";
  20.     if (test_string.match(/^[a-zA-Z0-9&_.-']+$/)){
  21.         alert("second test matched");
  22.     }else{
  23.         alert("second test did not match");
  24.     }
  25.  
  26.     //invalid - ! is not allowed
  27.     test_string = "'ThisIsNotValid!'";
  28.     if (test_string.match(/^[a-zA-Z0-9&_.-']+$/)){
  29.         alert("third test matched");
  30.     }else{
  31.         alert("third test did not match");
  32.     }
  33.  
  34. </script>
  35.        
  36. var regex = /^[a-z0-9_-.'&]/i;
  37.        
  38. /^[-w.'&]+$/