Regular Expression, Regular Expression
// The password containing numbers and letters is 6-16 characters long
-(BOOL) validatePassword :( NSString *) password
{
// Password Regular Expression
NSString * passwordRegex = @ "^ (? = .*? [A-zA-Z]) (? = .*? [0-9]) [a-zA-Z0-9] {6, 16} $ ";
NSPredicate * passwordTest = [NSPredicate predicateWithFormat: @ "self matches % @", passwordRegex];
Return [passwordTest evaluateWithObject: password];
}
-(BOOL) validateEmail :( NSString *) email
{
// Mailbox Regular Expression
NSString * emailRegex = @ "^ \ w + (-\ w +) | (\\. \ w +) * \ @ [A-Za-z0-9] + ((\\. |-) [A-Za-z0-9] + )*\\. [A-Za-z0-9] + $ ";
NSPredicate * emailTest = [NSPredicate predicateWithFormat: @ "self matches % @", emailRegex];
Return [emailTest evaluateWithObject: email];
}
// The mobile phone number must start with 11,12, 13,14, 15,16, 17,18, and 19.
-(BOOL) validateMobile :( NSString *) mobile
{
// Mobile phone Regular Expression
NSString * assumeregex = @ "^ (1 [123456789] [0-9] {9}) $ ";
NSPredicate * mobileTest = [NSPredicate predicateWithFormat: @ "self matches % @", assumeregex];
Return [mobileTest evaluateWithObject: mobile];
}
-(BOOL) validateTel :( NSString *) tel
{
// Fax, regular expression of landline phone
NSString * phoneRegex = @ "^ ([0 \ +] \ d {2, 3 }-)? (0 \ d {2, 3 })-)? (\ D {7, 8}) (-(\ d {3 ,}))? $ ";
NSPredicate * phoneTest = [NSPredicate predicateWithFormat: @ "self matches % @", phoneRegex];
Return [phoneTest evaluateWithObject: tel];
}