//Declaration
-(BOOL) isPasswordValid:(NSString *)pwd;
//Usage
int length=[passwordString length];
if( length<8 || length >10 || (![self isPasswordValid:passwordString])) {
NSString *alertMsg=@"Password length should be between 8 to 10 characters.Password must have at least 1 alphabet and 1 numeral(0-9)";
[AlertView showAlert:alertMsg WithDelegate:self andTag:555];
textField.text=@"";
}
//Method
-(BOOL) isPasswordValid:(NSString *)pwd{
NSRange rang;
isValid=YES;
rang = [pwd rangeOfCharacterFromSet:[NSCharacterSet letterCharacterSet]];
if (!rang.length ){
isValid=NO;// no letter
}
rang = [pwd rangeOfCharacterFromSet:[NSCharacterSet decimalDigitCharacterSet]];
if (!rang.length) {
isValid=NO; // no numb
}
return isValid;
}
No comments:
Post a Comment