/StringValidator

A small swift class providing quick regular expression checking.

Primary LanguageSwiftMIT LicenseMIT

A small swift class providing quick regular expression checking.

##Supported Regex

  • AlphaNumericAccentedCharacters (Alphabet, Numeric, and Accented Characters)
  • AlphaNumericAccentedCharactersWithSpaces
  • AlphaNumericWithSymbolsAndSpaces (AlphabetNumericAccentedCharactersWithSpaces with symbols)
  • Email
  • IPAddress
  • URL
  • ZipCodeUSA
  • ZipCodeAsia
  • Numeric (Whole and Decimal Numbers)
  • NumericWhole
  • PhoneNumber

##Example Usage ###Finding ranges in a string

let emailBody = "Sure thing! My email is johndoe@example.com, and Linsey's is linseydoe@example.com"

let emailRanges = emailValidation.validRangesInString(emailBody)

for range in emailRanges {
    let emailAddress = NSString(string: emailBody).substringWithRange(range)
    print (emailAddress)
}

###Validate text input

func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
    let backspacePressed = string.isEmpty
    
    let characterValidator = ValidationPolicy(conformsTo: RegexPattern.AlphaNumericAccentedCharactersWithSpaces)
    if characterValidator.validateString(string) || backspacePressed {
        return true
    }
    
    return false
}

###Validate an entire string

let ipAddress = "192.168.1.1"
let ipAddressValidator = ValidationPolicy(conformsTo: .IPAddress)

if ipAddressValidator.validateString(ipAddress) {
    print("Yup! That's a fine looking IP Address you got there.")
}

License

StringValidator is available under the MIT license. See the LICENSE file for more info.