One simple way would be to validate the string using this regular expression:
^[$][0-9]+([.][0-9]{2})?$
^ ^ ^ ^ ^ ^ ^ ^^
| | | | | | | ||
| | | | | | | |+-- End-of-input marker
| | | | | | | +--- Optional
| | | | | | +------ Repeated exactly two times
| | | | | +---------- A decimal digit
| | | | +-------------- A dot (literal)
| | | +----------------- Repeated once or more
| | +-------------------- A decimal digit
| +------------------------ The dollar sign (literal)
+-------------------------- Start-of-input marker
Here is a sample code that uses the above expression:
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression
regularExpressionWithPattern:@"^[$][0-9]+([.][0-9]{2})?$"
options:NSRegularExpressionCaseInsensitive
error:&error];
if ([regex numberOfMatchesInString:@"$321.05" options:0 range:NSMakeRange(0, 7)]) {
NSLog(@"Success");
}