Check NSString for special characters

NSCharacterSet * set = [[NSCharacterSet alphanumericCharacterSet] invertedSet]; if ([aString rangeOfCharacterFromSet:set].location != NSNotFound) { NSLog(@”This string contains illegal characters”); } You could also use a regex (this syntax is from RegexKitLite: http://regexkit.sourceforge.net ): if ([aString isMatchedByRegex:@”[^a-zA-Z0-9]”]) { NSLog(@”This string contains illegal characters”); }

Should we HTML-encode special characters before storing them in the database?

Don’t HTML-encode your characters before storage. You should store as pure a form of your data as possible. HTML encoding is needed because you are going to display the data on an HTML page, so do the encoding during the processing of the data to create the page. For example, suppose you decide you’re also … Read more

jQuery: Check if special characters exists in string

If you really want to check for all those special characters, it’s easier to use a regular expression: var str = $(‘#Search’).val(); if(/^[a-zA-Z0-9- ]*$/.test(str) == false) { alert(‘Your search string contains illegal characters.’); } The above will only allow strings consisting entirely of characters on the ranges a-z, A-Z, 0-9, plus the hyphen an space … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)