-1

Why is it taking range.length nil. I entered text Demo@123. In this special character is their but length will taking nil.

NSRange rang = [textField.text rangeOfCharacterFromSet:[NSCharacterSet symbolCharacterSet]];

if ( !rang.length ) {
    return NO;  // no specialCharacter
}
RameshIos
  • 301
  • 1
  • 4
  • 13
  • Check this answer - http://stackoverflow.com/questions/14557925/ios-how-to-restrict-special-characters-in-uitextfield-except-dot-and-underscores – Kampai Dec 05 '14 at 11:37

1 Answers1

0

NSRange is not an object, it's a struct. Lose the * character.

NSRange rang = ...

not

NSRange *rang = ...

You should be getting a warning for this.

Okey, going through the Unicode tables, it seems that @ is not a symbol character. It is categorized as punctuation ([NSCharacterSet punctuationCharacterSet]).

Sulthan
  • 118,286
  • 20
  • 194
  • 245