MmD
MmD

Reputation: 2154

allow english and arabic numbers input UITextField swift

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!

Upvotes: 3

Views: 1804

Answers (1)

MmD
MmD

Reputation: 2154

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
        }
    }

Upvotes: 1

Related Questions