ios常用正则表达式与左对齐的UIAlertView

+(BOOL)alertPhoneString:(NSString *)text  ifalert:(BOOL)ifalert

{//判断是手机号码

    

    

    if (text.length==0) {

        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"请填写手机号码" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

        [alert show];

        [alert release];

        return NO;

    }

    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\b(1)[3458][0-9]{9}\\b" options:NSRegularExpressionCaseInsensitive error:nil];

    NSUInteger numberOfMatches = [regex numberOfMatchesInString:text options:0 range:NSMakeRange(0, [text length])];

    if(numberOfMatches !=1 ){

        //手机号码错误

        if (ifalert) {

            //需要提醒手机号错误

            UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"请确认手机号码是否正确" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

            [alert show];

            [alert release];

        }

        return NO;

    }

    else

        return YES;

}


+(BOOL)alertEmail:(NSString *)EmailAddress ifalert:(BOOL)ifalert

{

//判断邮箱是否正确

    if (EmailAddress.length==0) {

        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"请填写邮箱!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

        [alert show];

        [alert release];

        return NO;

    }

    

    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}" options:NSRegularExpressionCaseInsensitive error:nil];

    NSUInteger numberOfMatches = [regex numberOfMatchesInString:EmailAddress options:0 range:NSMakeRange(0, [EmailAddress length])];

    if(numberOfMatches !=1 ){

        

        if (ifalert) {

        

            UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示"

                                                            message:@"邮箱格式不正确"

                                                           delegate:nil

                                                  cancelButtonTitle:@"确定"

                                                  otherButtonTitles:nil];

            

            [alert show];

            [alert release];

        

        }

        return NO;

    }

    else

        return YES;

}



+(BOOL)alertInputCardNo:(NSString *)string

{ //判断输入是否是正整数

    NSCharacterSet *cs;

    cs = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789\n"] invertedSet];

    NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];

    BOOL basicTest = [string isEqualToString:filtered];

    if(!basicTest)

    {

        UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"输入只能为数字"

                                                       delegate:nil

                                              cancelButtonTitle:@"确定"                                              otherButtonTitles:nil];

        

        [alert show];

        [alert release];

        return NO;

    }

    else

        return YES;

}



+(BOOL)alertresult:(NSString *)message title:(NSString *)title

{

    //message的格式为 /n*****/n****/n*** 该alert的显示格式为

  //  *****

  //  ****

  //  ***

   

    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:title message:message delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

  

    for( UIView * view in alert.subviews )

    {

        if( [view isKindOfClass:[UILabel class]] )

        {

            UILabel* label = (UILabel*) view;

            if (label.text!=alert.title) {

                label.textAlignment = UITextAlignmentLeft;

           

            }

            

        }

        

    }

    [alert show];

    [alert release];

    return YES;


}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值