(ext.) iOS development mailbox, phone number, ID, password, nickname regular expression validation

Source: Internet
Author: User

I've seen that before.


2345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656 6676869707172737475767778
//邮箱+ (BOOL) validateEmail:(NSString *)email{    NSString *emailRegex = @"[A-Z0-9a-z._%+-][email protected][A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];    return[emailTest evaluateWithObject:email];}  //手机号码验证+ (BOOL) validateMobile:(NSString *)mobile{    //手机号以13, 15,18开头,八个 \d 数字字符    NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];    return[phoneTest evaluateWithObject:mobile];}  //车牌号验证+ (BOOL) validateCarNo:(NSString *)carNo{    NSString *carRegex = @"^[\u4e00-\u9fa5]{1}[a-zA-Z]{1}[a-zA-Z_0-9]{4}[a-zA-Z_0-9_\u4e00-\u9fa5]$";    NSPredicate *carTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",carRegex];    NSLog(@"carTest is %@",carTest);    return[carTest evaluateWithObject:carNo];}  //车型+ (BOOL) validateCarType:(NSString *)CarType{    NSString *CarTypeRegex = @"^[\u4E00-\u9FFF]+$";    NSPredicate *carTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",CarTypeRegex];    return[carTest evaluateWithObject:CarType];}  //用户名+ (BOOL) validateUserName:(NSString *)name{    NSString *userNameRegex = @"^[A-Za-z0-9]{6,20}+$";    NSPredicate *userNamePredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",userNameRegex];    BOOLB = [userNamePredicate evaluateWithObject:name];    returnB;}  //密码+ (BOOL) validatePassword:(NSString *)passWord{    NSString *passWordRegex = @"^[a-zA-Z0-9]{6,20}+$";    NSPredicate *passWordPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",passWordRegex];    return[passWordPredicate evaluateWithObject:passWord];}   //昵称+ (BOOL) validateNickname:(NSString *)nickname{    NSString *nicknameRegex = @"^[\u4e00-\u9fa5]{4,8}$";    NSPredicate *passWordPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",nicknameRegex];    return[passWordPredicate evaluateWithObject:nickname];}  //身份证号+ (BOOL) validateIdentityCard: (NSString *)identityCard{    BOOLflag;    if(identityCard.length <= 0) {        flag = NO;        returnflag;    }    NSString *regex2 = @"^(\\d{14}|\\d{17})(\\d|[xX])$";    NSPredicate *identityCardPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex2];    return[identityCardPredicate evaluateWithObject:identityCard];}

(ext.) iOS development mailbox, phone number, ID, password, nickname regular expression validation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.