How to Validate Symbol Characterset in Objective c?

1k views Asked by At

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

There are 1 answers

1
Sulthan On

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]).