String format compare in objective c
hello all i have one NSString
in this for开发者_C百科mat +1-123-123-1234
(phone number US base style) , my question is How can we compare that my string is formted in +1-123-123-1234
format .
on the basic of String compare formatted i have to done another task ..so any one have any idea regarding same please help me .
You can use a NSRegularExpression
to test if your string is of a certain format.
NSRegularExpression *regex = [NSRegularExpression
regularExpressionWithPattern:@"^\\+\\d-\\d{3}-\\d{3}-\\d{4}$"
options:NSRegularExpressionCaseInsensitive
error:nil];
int num = [regex numberOfMatchesInString:phoneNumberHere
options:0
range:NSMakeRange(0, [phoneNUmberHere length])];
if (num == 1) {
// match!
}
精彩评论