iOS中的邮政编码验证 [英] Postal Code Validation in iOS

查看:186
本文介绍了iOS中的邮政编码验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为iOS 7开发一个应用程序,我想在其中检索用户位置详细信息。
现在我还想要用户的邮政编码。我只想检查用户输入的邮政编码是否有效的页面。
我想验证美国和英国。
如何实现这个目标?

I am developing an app for iOS 7 in which I want to retrieve user location details. Now I also want postal code of user. And I want to check on only that page that postal code entered by the user is valid or not. I want to validate for US and UK. How to achieve this?

推荐答案

对于印度,您可以使用以下方法验证密码

For India, you can use the below method to validate the pincode

-(BOOL)isValidPinCode:(NSString*)pincode    {
    NSString *pinRegex = @"^[0-9]{6}$";
    NSPredicate *pinTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pinRegex];

    BOOL pinValidates = [pinTest evaluateWithObject:pincode];
    return pinValidates;
}

对于美国,您可以使用

^\d{5}(-\d{4})?$

对于英国,请使用此

^([A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])\ [0-9][ABD-HJLNP-UW-Z]{2}|(GIR\ 0AA)|(SAN\ TA1)|(BFPO\ (C\/O\ )?[0-9]{1,4})|((ASCN|BBND|[BFS]IQQ|PCRN|STHL|TDCU|TKCA)\ 1ZZ))$

这篇关于iOS中的邮政编码验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆