Simple phone number validation in swift ios 8 , Using this function you can easily check phone number . Also have some example for this using NSPredicate etc .
you can see lots of method for number validation. But I made this sort method
func phoneNumberValidation(value: String) -> Bool {
var charcter = NSCharacterSet(charactersInString: “0123456789”).invertedSet
var filtered:NSString!
var inputString:NSArray = value.componentsSeparatedByCharactersInSet(charcter)
filtered = inputString.componentsJoinedByString(“”)
return value == filtered
}
How to use this validation function in code
if self.phoneNumberValidation(contactNumTextF.text) == false {
let alert = UIAlertView()
alert.title = “Message”
alert.message = “Enter Valid Contact Number”
alert.addButtonWithTitle(“Ok”)
alert.delegate = self
alert.show()
}else {
// Number valid? }