Check if NSString contains alphanumeric + underscore characters only

后端 未结 7 1753
余生分开走
余生分开走 2021-01-30 00:52

I\'ve got a string that needs to be only a-z, 0-9 and _

How do I check if the input is valid? I\'ve tried this but it accepts letter like å,ä,ö,ø etc.

NS         


        
7条回答
  •  花落未央
    2021-01-30 01:27

    Create your own character set using [NSCharacterSet characterSetWithCharactersInString:], then trim as you were doing to see if the returned string has a length value.

    Or you could use invertedSet to remove all non-set characters, if that would help to produce a cleaned string.

提交回复
热议问题