Monday, 23 April 2012

Limit number of characters in uitextview

if(range.length > text.length){
    return YES;
}else if([[textView text] length] + text.length > 140){
    return NO;
}
return YES;

Sunday, 22 April 2012

Monday, 16 April 2012

Email and URL Validation in Objective-C

Use this Code for Email Validation:

- (BOOL) validateEmail: (NSString *) candidate {
    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex]; 
    return [emailTest evaluateWithObject:txtEmail.text];
}


Use this Code for URL Validation:


- (BOOL) validateUrl: (NSString *) candidate {
    NSString *urlRegEx =@"(http|https)://((\\w)*|([0-9]*)|([-|_])*)+([\\.|/]((\\w)*|([0-9]*)|([-|_])*))+";
    NSPredicate *urlTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", urlRegEx];
    return [urlTest evaluateWithObject:txtUrl.text];
}

Thursday, 12 April 2012

Check if NSString is numeric(integer or float)


NSScanner *scan = [NSScanner scannerWithString:@"string"];

if (![scan scanFloat:NULL] || ![scan isAtEnd])
{
   NSlog (@"string exist like 'abbc','12ww','1.5w',' 5 ' etc");
}
else
{
       NSlog (@"only numeric value like '12','12.5','1.5' etc");
}

Flip clock with Core Animation in iOS Apps


Creating an iPad flip-clock with Core Animation

Check this Link:
http://www.voyce.com/index.php/2010/04/10/creating-an-ipad-flip-clock-with-core-animation/