带09前缀的11位电话号码的正则表达式 [英] Reqular expression for 11 digit phone number with 09 prefix
本文介绍了带09前缀的11位电话号码的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写一个正则表达式来处理以"0"开头,后跟"9"和9位数字(可以是0-9之间的任何数字)的电话号码.
I am trying to write a regular expression to handle phone number which starts with "0" followed by "9" and 9 digits which can be anything within 0-9.
-(BOOL) validateAlphabets: (NSString *)text{
NSString *Regex = @"what should be here?!";
NSPredicate *TestResult = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", Regex];
return [TestResult evaluateWithObject:text];
}
然后我通过以下方式检查输入验证:
Then I check the input validation by:
if (![self validateAlphabets:self.phoneNumber.text]){
NSLog(@"Invalid");
}
else{
NSLog(@"Valid!");
}
推荐答案
您可以尝试使用此正则表达式:
You can try to use this Regex:
09[0-9]{9}
REGEX DEMO
您可以尝试在函数本身中对其进行测试,如下所示:
You can try to test it in your function itself like this:
-(BOOL) validateAlphabets: (NSString *)text{
NSString *Regex = @"what should be here?!";
NSPredicate *TestResult = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", Regex];
if(TestResult evaluateWithObject: text)
return true;
else
return false;
}
这篇关于带09前缀的11位电话号码的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文