[Code Note] verifies the mobile phone number, email address, license plate number, and license plate number.

Source: Internet
Author: User

[Code Note] Verify whether the mobile phone number, mailbox, license plate number is legal, mobile phone license plate number

One, the code.

-(void) viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    NSLog (@ "------% d ------", [self isValidateEmail: @ "12345"]);
    NSLog (@ "------% d ------", [self isValidateMobile: @ "12345"]);
    NSLog (@ "---% d ---------", [self isValidateCar: @ "12345"]);
    
}

#pragma -mark-Email verification
-(BOOL) isValidateEmail: (NSString *) email
{
    NSString * emailRegex = @ "[A-Z0-9a-z ._% +-] + @ [A-Za-z0-9 .-] + \\. [A-Za-z] {2,4}" ;
    NSPredicate * emailTest = [NSPredicate predicateWithFormat: @ "SELF MATCHES% @", emailRegex];
    return [emailTest evaluateWithObject: email];
}

#pragma -mark-mobile phone number verification
-(BOOL) isValidateMobile: (NSString *) mobile
{
    // The phone number starts with 13, 15, 18, and eight \ d numeric characters
    NSString * phoneRegex = @ "^ ((13 [0-9]) | (15 [^ 4, \\ D]) | (18 [0,0-9])) \\ d {8} $";
    NSPredicate * phoneTest = [NSPredicate predicateWithFormat: @ "SELF MATCHES% @", phoneRegex];
    // NSLog (@ "phoneTest is% @", phoneTest);
    return [phoneTest evaluateWithObject: mobile];
}

#pragma -mark-License plate number verification
-(BOOL) isValidateCar: (NSString *) car
{
    NSString * carRegex = @ "^ [A-Za-z] {1} [A-Za-z_0-9] {5} $";
    NSPredicate * carTest = [NSPredicate predicateWithFormat: @ "SELF MATCHES% @", carRegex];
    NSLog (@ "carTest is% @", carTest);
    return [carTest evaluateWithObject: car];
}
 

Second, the output.

2015-10-22 10: 00: 05.694 Verify that the mobile phone number, mailbox, and license plate number are legal [1459: 49136] ------ 0 ------
2015-10-22 10: 00: 05.694 Verify that the mobile phone number, mailbox, and license plate number are legal [1459: 49136] ------ 0 ------
2015-10-22 10: 00: 05.695 Verify the phone number, email address, and license plate number are legal [1459: 49136] carTest is SELF MATCHES "^ [A-Za-z] {1} [A-Za-z_0-9] {5} $ "
2015-10-22 10: 00: 05.695 Verify that the mobile phone number, mailbox, and license plate number are legal [1459: 49136] --- 0 ---------


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.