name and email validation

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
if (textField==self.name_TxtField)
{
NSString *nameRegex=@"[A-Za-z ]*";
nameTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", nameRegex];

if ([nameTest evaluateWithObject:self.name_TxtField.text]==NO)
{
[self alertStatus:@"Enter Valid Name" :@"Warning" :nil :@"OK"];

return NO;
}
}
else if (textField==self.phone_TxtFeild)
{
NSString *phoneRegex = @"^[7-9][0-9]{9}$";
phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", phoneRegex];
if ([phoneTest evaluateWithObject:self.phone_TxtFeild.text]==NO)
{
[self alertStatus:@"Enter Valid Mobile Number" :@"Warning" :nil :@"OK"];

return NO;
}


}

else if (textField==self.email_TxtField)
{
//
BOOL stricterFilter = NO;
NSString *stricterFilterString = @"^[A-Z0-9a-z\\._%+-]+@([A-Za-z0-9-]+\\.)+[A-Za-z]{2,4}$";
NSString *laxString = @"^.+@([A-Za-z0-9-]+\\.)+[A-Za-z]{2}[A-Za-z]*$";
NSString *emailRegex = stricterFilter ? stricterFilterString : laxString;
// NSString *emailRegex=@"[A-Z0-9a-z._%+-]+@[A-Za-z.]+\\.[A-Za-z]{2,6}";
emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];

if ([emailTest evaluateWithObject:self.email_TxtField.text]==NO)
{
[self alertStatus:@"Enter Valid Email Id" :@"Warning" :nil :@"OK"];

return NO;
}
}
else if (textField==self.reference_TxtField)
{
NSString *phoneRegex=@"[0123456789]*";
phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", phoneRegex];

if ([phoneTest evaluateWithObject:self.reference_TxtField.text]==NO)
{
[self alertStatus:@"Enter Valid Reference Phone Number" :@"Alert" :nil :@"OK"];

return NO;
}
}
return YES;
}
Previous
Next Post »