title: How do I check UITextField values for specific types of characters e.g. Letters or Number?
body: <p>What I want to do is set some boolean in the if statement below to true if anything other than letters, numbers, dashes and spaces is contained in the textField.</p>
  
  <p>Then for an email field check for a valid email.</p>
  
  <p><strong>This is how I'm checking for length:</strong></p>
  
  <pre><code>    if countElements(textField.text!) &lt; 2 || countElements(textField.text) &gt; 15 {
          errorLabel.text = "Name must have between 2 and 15 characters."
          self.signUpView.signUpButton.enabled = false
      } else {
          errorLabel.text = ""
          self.signUpView.signUpButton.enabled = true
      }
  </code></pre>
  
  <p>This if statement is inside the UITextFieldDelegate method textFielddidEndEditing. I have a feeling I'll have to use some form of regex to check for a valid email.</p>
  
  <p>Would it make sense to use a regex to check a field only contains the characters I allow and return a boolean that'll tell me if the text field contains disallowed characters so I can then show an error message.</p>
  
  <p>Is there some preferred way to do this? In objective-c I used NSCharacterSet but not sure how to implement that here. </p>
  
  <p>Thanks for your time</p>