Hi,
I need a regular expression to detect at least one number in a string. Other characters can be anything. Please help me to implement this in objective C.
Regards,
Dilshan
Hi,
I need a regular expression to detect at least one number in a string. Other characters can be anything. Please help me to implement this in objective C.
Regards,
Dilshan
This is a very similar question to:
Regular Expressions in Objective-C and Core Data
Check ICU Regex Documentation for figuring out your regular expression needs
To match a digit anywhere in string use .*\\d.*
. To implement in objective-c use NSPredicate
try something like this:
NSString *matchphrase = @".*\\d.*";
BOOL match = NO;
NSString *item = @"string with d1g1it";
NSPredicate *matchPred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", matchphrase];
match = [matchPred evaluateWithObject:item];
More here
Edited according Dislhan comment.