title: Powershell - Remove everything but A-Z, - and space with Regex
body: <p>I'm pretty new to programming in powershell and regex in general. Can a kind soul please explain to me why the following doesn't work?</p>
  
  <pre><code>while($true) {
      $Name = Read-Host "Please enter your firstname and lastname"
  
      if($Name -match "[^a-zA-Z-]" -and $Name -match " ") {
          break;
      } else {
          Write-Host -ForegroundColor red "You didn't enter a valid name! Please try again."
      }
  }
  </code></pre>
  
  <p>I want my code to keep asking for first and surname as long as it has characters that are not a-z and - along with a space in it. Am I taking the wrong approach here?</p>
  
  <p>Woops, should probably have mentioned the error. I can add numbers and special symbols (like >&lt;\^€$ etc.). It only gives me the error in else when I'm not adding in a space in the $name string</p>