Iphone registration verification (regular)

Source: Internet
Author: User

 

Java code

Recently, I was working on a user management program. During the process, I checked the user registration information on the Internet for a long time. I didn't find the ready-made code, but I had to write it myself,

 

Recently, I was working on a user management program. During the process, I checked the user registration information on the Internet for a long time. I didn't find the ready-made code, but I had to write it myself. Java code

Put the code here and take it directly. Back up your own data for future use.

 

Put the code here and take it directly. Back up your own data for future use. Java code

// Verify the user name

+ (BOOL) validateUserName: (NSString *) str

{

NSString * patternStr = [NSString stringWithFormat: @ "^. {0, 4 }$ |. {21,} | ^ [^ A-Za-z0-9 \ u4E00-\ u9FA5] | [^ \ w \ u4E00-\ u9FA5. -] | ([_. -]) \ 1 "];

NSRegularExpression * regularexpression = [[NSRegularExpression alloc]

InitWithPattern: patternStr

Options: NSRegularExpressionCaseInsensitive

Error: nil];

NSUInteger numberofMatch = [regularexpression numberOfMatchesInString: str

Options: NSMatchingReportProgress

Range: NSMakeRange (0, str. length)];

[Regularexpression release];

If (numberofMatch> 0)

{

Return YES;

}

Return NO;

}

 

// Verify the User Password

+ (BOOL) validateUserPasswd: (NSString *) str

{

NSRegularExpression * regularexpression = [[NSRegularExpression alloc]

InitWithPattern: @ "^ [a-zA-Z0-9] {6, 16} $"

Options: NSRegularExpressionCaseInsensitive

Error: nil];

NSUInteger numberofMatch = [regularexpression numberOfMatchesInString: str

Options: NSMatchingReportProgress

Range: NSMakeRange (0, str. length)];

[Regularexpression release];

If (numberofMatch> 0)

{

NSLog (@ "% @ isNumbericString: YES", str );

Return YES;

}

NSLog (@ "% @ isNumbericString: NO", str );

Return NO;

}

 

// Verify the user's birthday

+ (BOOL) validateUserBornDate: (NSString *) str

{

NSString * patternStr = @ "^ (1 [6-9] | [2-9] \ d) \ d {2})-(0? [1, 13578] | 1 [02])-(0? [1-9] | [12] \ d | 3 [01]) | (1 [6-9] | [2-9] \ d) \ d {2})-(0? [13456789] | 1 [012])-(0? [1-9] | [12] \ d | 30) | (1 [6-9] | [2-9] \ d) \ d {2})-0? 2-(0? [1-9] | 1 \ d | 2 [0-8]) | (1 [6-9] | [2-9] \ d) (0 [48] | [2468] [048] | [13579] [26]) | (16 | [2468] [048] | [3579] [26]) 00)-0? 2-29-) $ ";

NSRegularExpression * regularexpression = [[NSRegularExpression alloc]

InitWithPattern: patternStr

Options: NSRegularExpressionCaseInsensitive

Error: nil];

NSUInteger numberofMatch = [regularexpression numberOfMatchesInString: str

Options: NSMatchingReportProgress

Range: NSMakeRange (0, str. length)];

[Regularexpression release];

If (numberofMatch> 0)

{

NSLog (@ "% @ isNumbericString: YES", str );

Return YES;

}

NSLog (@ "% @ isNumbericString: NO", str );

Return NO;

}

 

// Verify the user's mobile phone number

+ (BOOL) validateUserPhone: (NSString *) str

{

NSRegularExpression * regularexpression = [[NSRegularExpression alloc]

InitWithPattern: @ "(\ d {11}) | ^ (\ d {7, 8}) | (\ d {4} | \ d {3 }) -(\ d {7,8}) | (\ d {4} | \ d {3})-(\ d {7,8 }) -(\ d {4} | \ d {3} | \ d {2} | \ d {1}) | (\ d {7, 8 }) -(\ d {4} | \ d {3} | \ d {2} | \ d {1}) $ )"

Options: NSRegularExpressionCaseInsensitive

Error: nil];

NSUInteger numberofMatch = [regularexpression numberOfMatchesInString: str

Options: NSMatchingReportProgress

Range: NSMakeRange (0, str. length)];

[Regularexpression release];

If (numberofMatch> 0)

{

NSLog (@ "% @ isNumbericString: YES", str );

Return YES;

}

NSLog (@ "% @ isNumbericString: NO", str );

Return NO;

}

 

// Verify the user's email address

+ (BOOL) validateUserEmail: (NSString *) str

{

NSRegularExpression * regularexpression = [[NSRegularExpression alloc]

InitWithPattern: @ "\ w + ([-+.] \ w +) * @ \ w + ([-.] \ w + )*\\. \ w + ([-.] \ w + )*"

Options: NSRegularExpressionCaseInsensitive

Error: nil];

NSUInteger numberofMatch = [regularexpression numberOfMatchesInString: str

Options: NSMatchingReportProgress

Range: NSMakeRange (0, str. length)];

[Regularexpression release];

If (numberofMatch> 0)

{

NSLog (@ "% @ isNumbericString: YES", str );

Return YES;

}

NSLog (@ "% @ isNumbericString: NO", str );

Return NO;

}

 

 

Author HOTFM

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.