2012-01-25 34 views
0

我正在使用RegexKitLite,我想驗證我的uitextfield有+前綴並且包含數字長度爲13或只有13個數字值。如何正確使用RegexKitLite

請讓我知道

下面是我試圖

textview.text = @"123458kdkmfmdfmsdf" 

NSString *regEx = @"{3}-[0-9]{3}-[0-9]{4}"; 
NSString *match = [textView.text stringByMatching:regEx]; 
if ([match isEqual:@""] == NO) 
{ NSLog(@"Phone number is %@", match); } 
else { NSLog(@"Not found."); } 
代碼

我想要的輸出中是貝羅 輸出中1 =「1234567891012」 或輸出2可以像「1234567891012

+0

你想添加只有13個數字埃裏克值或任何?給我你想要的輸出 – 2012-01-25 05:31:57

回答

1

試試這個:

NSString * forAlphaNumeric = @"^([+]{1})(a-zA-Z0-9{13})$"; 
BOOL isMatch = [yourString isMatchedByRegex:forAlphaNumeric]; 

NSString * forNumeric = @"^([+]{1})(0-9{13})$"; 
BOOL isMatch = [yourString isMatchedByRegex:forNumeric];