Phone number validation and formatting on iOS

Viewed 1543

I am using this library https://github.com/me2day/libPhoneNumber-iOS for validating the phone numbers.

I want to ask is that on whatsapp If you enter a phone number digits greater or less than the original Phone number of some country it shows error and give you a message that the digits are less than or greater than. How can I do this? how can I figure out the number of digits in phone number used in particular country and gives error according to that.

At the moment I am validating the phone number of country like this

let phoneUtil = NBPhoneNumberUtil.sharedInstance()

do {
    let number:NBPhoneNumber = try phoneUtil.parse(phoneNumber, defaultRegion:countryCode)

    let isValidNumber: Bool = phoneUtil.isValidNumberForRegion(number, regionCode: countryCode)

    return isValidNumber
}catch  let error as NSError {
    print(error.localizedDescription)
    return false
}
0 Answers
Related