如何正确使用RegexKitLite

发布于 2024-12-28 23:12:39 字数 457 浏览 0 评论 0原文

我正在使用 RegexKitLite,我想验证我的 uitextfield 是否有 + 前缀,并且包含数字长度为 13 或仅包含 13 个数字值。

请让我知道

下面是我尝试的代码,

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."); }

我想要的输出是 belo 输出 1 =“1234567891012” 或者输出 2 可以类似于“+1234567891012

I am using RegexKitLite, i want to validate that my uitextfield has + prefixed and contains numeric length of 13 or only 13 numeric values.

Please let me know

Below is the code i tried

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."); }

the ouput i want is belo
ouput 1 = "1234567891012"
or output 2 can be like "+1234567891012

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

私藏温柔 2025-01-04 23:12:39

试试这个:

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

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

try this :

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

NSString * forNumeric = @"^([+]{1})(0-9{13})$";
BOOL isMatch = [yourString isMatchedByRegex:forNumeric];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文