Wednesday 18 December 2013

Validation for allow only numeric value in IPhone

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    NSString *phoneRegex = @"^([0-9]+)?(\\.([0-9]{1,2})?)?$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", phoneRegex];
   
    if([phoneTest evaluateWithObject:textField.text]==NO)
    {
        UIAlertView *alertView = [[UIAlertView alloc]
                                  initWithTitle:@"Validation" message:@"Only Number allow."
                                  delegate:self cancelButtonTitle:@"Yes" otherButtonTitles:nil, nil];
       
        [alertView show];
        [textField becomeFirstResponder];
    }
}

No comments:

Post a Comment

Comment