0

似乎无法弄清楚如何检查字符串,以便不允许连续出现相同的两个字符。

我不希望任何人能够使用“00”提交数据。

4

1 回答 1

1

What about just:

(\d)\1+

The \d matches any digit and the \1+ matches whatever was matched in the first bit when it appears more than one time.


Pertaining to your comments though, it's much easier just to check:

if ([expiryDate rangeOfString:@"00"].location != NSNotFound)
{
    //Invalid date
}

or even perhaps more validating:

NSArray *components = [expiryDate componentsSeparatedByString:@"/"];
int month = [components[0] intValue];
int year = [components[1] intValue];
NSAssert(month > 0 && month <= 12, @"Invalid Month");
NSAssert(year >= 13 /*current year*/ /* (optionally) && year < 20 (or some other future year)*/, @"Invalid year");
于 2013-11-01T17:00:55.180 回答