title: How to validate regular expression having only special character in angularjs?
body: <p>I have to do validation for particular text value. If string is empty, i have to return as please enter some value. The text field should allow alphanumeric and special characters .@_ .If user enter any other special character, need to return special characters except .@_ not allowed. And if they enter only special characters, i have to return 'do not enter special char'? I tried below method, but i did not work out. Any help pls?</p>
  
  <p>Please see updated code here.</p>
  
  <pre><code>const test1 = '[^A-Za-z0-9_||@||\. ]';
  const test2 = '[A-Za-z0-9]';
  const whitespace = '/^\s*$/';
  const onlyspecial = '/[.@_ ]/';
  
  if(strval.match(whitespace))
  {
      return "Please enter value";
  }
  if(strval.match(test1))
  {
      if(strval.match(test2)|| strval.match(onlyspecial))
      {
          return "special character except @,space,underscore and . not allowed";
      }
      else
      {
          return "do not enter only special char";
      }
  }
  
  Results for various input:
  
  strval = "abcd@123" - pass
  strval = "abcd_123" - pass
  strval= "abcd test" - pass
  strval = "abcd.test - pass
  strval = .@_   - do not enter only special char (though it is acceptable characters, only entering these should not accept)
  strval = "abcd$%^" - special character except @,space,underscore and . not allowed
  strval = "abcs2323&amp;&amp;" - special character except @,space,underscore and . not allowed
  strval = "$$$%%^&amp;&amp;"  - do not enter only special char
  strval = ".@_1234"  - please enter valid name
  </code></pre>