chronotruck / FlagPhoneNumber

A formatted phone number UITextField with country flag picker.
Apache License 2.0
437 stars 317 forks source link

Mobile number validation #180

Open nigamsiddhant opened 3 years ago

nigamsiddhant commented 3 years ago

Philippines and some other country mobile number is giving false result even the number is correct.

Have changed in fpntextfield.swift

let example = try phoneUtil.getExampleNumber(forType: countryCode.rawValue, type: NBEPhoneNumberType.MOBILE)

private func updatePlaceholder() {
      if let countryCode = selectedCountry?.code {
          do {
              let example = try phoneUtil.getExampleNumber(forType: countryCode.rawValue, type: NBEPhoneNumberType.MOBILE)
              let phoneNumber = "+\(example.countryCode.stringValue)\(example.nationalNumber.stringValue)"

              if let inputString = formatter?.inputString(phoneNumber) {
                  placeholder = remove(dialCode: "+\(example.countryCode.stringValue)", in: inputString)
              } else {
                  placeholder = nil
              }
          } catch _ {
              placeholder = nil
          }
      } else {
          placeholder = nil
      }
  }

Simulator Screen Shot - iPhone SE (2nd generation) - 2021-03-28 at 17 19 31