Hi i am beginner in Ios and in my project login page there is textfields validations(here i have two textfields they are medicaId,password)
my medicaid must allows only numbers and medicaId starts with 10 and ends with 99 if not then i want show alert Invalid medicaId
but according to my experience i could able to do only textfield allows numbers but i am not understand how to do that textfield(my medicaid) starts with 10 and ends with 99 please help me some one
my code:-
#import "ViewController.h"
@interface ViewController ()
#define ACCEPTABLE_CHARECTERS @"0123456789"
@end
@implementation ViewController
@synthesize textfield;
- (void)viewDidLoad {
[super viewDidLoad];
textfield.delegate = self;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if (textField==textfield)
{
NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:ACCEPTABLE_CHARECTERS] invertedSet];
NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
return [string isEqualToString:filtered];
}
return YES;
}
-(IBAction)CickMe:(id)sender{
if (success) {
NSLog(@"validations are perfect");
}else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"MedicaId must starts with 10 and ends with 99" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Cancel", nil];
[alert show];
}
}