Code for password validation is as below, written in textFieldDidEndEditing method of UITextField delegate :
*viewcontroller.h
Example :
*viewcontroller.m
- (void)textFieldDidEndEditing:(UITextField *)textField
*viewcontroller.h
Example :
@interface SignUpViewController : UIViewController<UITextFieldDelegate>
@property (nonatomic,retain)IBOutlet UITextField *pwd;
@synthesize pwd;
- (void)textFieldDidEndEditing:(UITextField *)textField
{
if (textField == pwd)
{
int numberofCharacters = 0;
BOOL lowerCaseLetter,upperCaseLetter= 0;
if([pwd.text length] >= 10)
{
for (int i = 0; i < [pwd.text length]; i++)
{
unichar c = [pwd.text characterAtIndex:i];
if(!lowerCaseLetter)
{
lowerCaseLetter = [[NSCharacterSet lowercaseLetterCharacterSet] characterIsMember:c];
}
if(!upperCaseLetter)
{
upperCaseLetter = [[NSCharacterSet uppercaseLetterCharacterSet] characterIsMember:c];
}
/*if(!digit)
{
digit = [[NSCharacterSet decimalDigitCharacterSet] characterIsMember:c];
}
if(!specialCharacter)
{
specialCharacter = [[NSCharacterSet symbolCharacterSet] characterIsMember:c];
}*/
}
if(lowerCaseLetter && upperCaseLetter)
{
//do what u want
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Please Ensure that you have at least one lower case letter, one upper case letter, one digit and one special character"
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Please Enter at least 10 password"
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
}
}
No comments:
Post a Comment