3

I write code that only allow english number in UITextField and I want to check arabic numbers and allow thats.

this is my code :

func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {

        let textString = "0123456789_"
        let cs : NSCharacterSet = NSCharacterSet(charactersInString: textString).invertedSet

        let filter = string.componentsSeparatedByCharactersInSet(cs).joinWithSeparator("") as String

        return string == filter
    }

in my code I want allow english number and remove button now I want add arabic numbers in it. I try with this : let textString = "0123456789_۰۱۲۳۴۵۶۷۸۹" but this not working!

MmD
  • 2,044
  • 5
  • 22
  • 41
  • 1
    Have you set a breakpoint and stepped through to see what is happening? What do you mean "not working"? – Paulw11 Aug 14 '16 at 09:34
  • @Paulw11 when input is one of ۰۱۲۳۴۵۶۷۸۹ return false and don't allow show it. – MmD Aug 14 '16 at 09:40

1 Answers1

1

I got it !!! hahahahahaha :D

func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {

//        let textString = "0123456789_۰۱۲۳۴۵۶۷۸۹"
        let cs : NSCharacterSet = NSCharacterSet.decimalDigitCharacterSet().invertedSet

        if string.rangeOfCharacterFromSet(cs) == nil {
            return true
        } else {
            return false
        }
    }
MmD
  • 2,044
  • 5
  • 22
  • 41