我是靠谱客的博主 美丽花卷,最近开发中收集的这篇文章主要介绍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:@"0123456789n"] 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;
}


最后

以上就是美丽花卷为你收集整理的ios常用正则表达式与左对齐的UIAlertView的全部内容,希望文章能够帮你解决ios常用正则表达式与左对齐的UIAlertView所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(54)

评论列表共有 0 条评论

立即
投稿
返回
顶部