iPhone SDK Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsMobile ProgrammingiPhone SDK Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 12th, 2010, 01:11 PM
zacharyrs zacharyrs is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2009
Posts: 2 zacharyrs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 53 sec
Reputation Power: 0
Help With Multiple Text Field Valdiation

I have five fields I need to validate, as different fields require a different range of numbers to have input by the user. The idea is when the user clicks to the next field it checks the previous field, however this isn't how it's working Is there a better way in my code to do this? I'd also like it when the user hits wrong info and disregards the error messages, it doesn't allow them to go to the next field.

Below is my code:

Code:
- (void)textFieldDidEndEditing:(UITextField *)textField
{	
	//NSLog(@"BundlePath: %@", [[NSBundle mainBundle] bundlePath]);
	
	//declare the vars
	NSString *userNameOne = txtUserName.text;
	float numOne = [userNameOne intValue];			//age in years
	NSString *userNameTwo = txtUserName2.text;
	float numTwo = [userNameTwo intValue];			//iop
	NSString *userNameThree = txtUserName3.text;
	float numThree = [userNameThree intValue];		//cct
	NSString *userNameFour = txtUserName4.text;	
	float numFour = [userNameFour intValue];		//psd
	NSString *userNameFive = txtUserName5.text;
	float numFive = [userNameFive intValue];

	
	if(numOne < 40 || numOne > 100)
	{
			
		//play sound and vibrate for alert
		NSString *bonkSoundFile = [[NSBundle mainBundle] pathForResource:@"alertSound" ofType:@"mp3"];
		NSURL *fileURL = [NSURL fileURLWithPath:bonkSoundFile];
		SystemSoundID  bonkSoundID;
		AudioServicesCreateSystemSoundID( (CFURLRef) fileURL, &bonkSoundID);
		AudioServicesPlaySystemSound(bonkSoundID);
		AudioServicesPlaySystemSound (kSystemSoundID_Vibrate);	//vibrate
		
		//show alert
		UIAlertView *alert = [[UIAlertView alloc]
							  initWithTitle:@"Age Error"
							  message:@"Your age must be at least 40 years old and less than 100 years old"
							  delegate:nil
							  cancelButtonTitle:@"OK"
							  otherButtonTitles:nil];
		[alert show];
		[alert release];
	}
	
	else if (numTwo < 20 || numTwo > 32)
	{
		UIAlertView *alert = [[UIAlertView alloc]
							  initWithTitle:@"IOP Error"
							  message:@"Your IOP must be between 20 and 32"
							  delegate:nil
							  cancelButtonTitle:@"OK"
							  otherButtonTitles:nil];
		[alert show];
		[alert release];
	}
	
	else if (numThree < 475 || numThree > 650)
	{
		UIAlertView *alert = [[UIAlertView alloc]
							  initWithTitle:@"CCT Error"
							  message:@"Your CCT must be between 475 and 650"
							  delegate:nil
							  cancelButtonTitle:@"OK"
							  otherButtonTitles:nil];
		[alert show];
		[alert release];
	}
	
	else if (numFour < .50 || numFour > 3.00)
	{
		UIAlertView *alert = [[UIAlertView alloc]
							  initWithTitle:@"PSD Error"
							  message:@"Your PSD must be between .50 and 3.00"
							  delegate:nil
							  cancelButtonTitle:@"OK"
							  otherButtonTitles:nil];
		[alert show];
		[alert release];
	}
	
	else if (numFive < 0.80)
	{
		UIAlertView *alert = [[UIAlertView alloc]
							  initWithTitle:@"C/D Error"
							  message:@"Your C/D must be between 0 and .80"
							  delegate:nil
							  cancelButtonTitle:@"OK"
							  otherButtonTitles:nil];
		[alert show];
		[alert release];
	}
}


And you can see a video of how it works (rather buggy)
http://screencast.com/t/NWNjZTU2M

Any advice would be greatly appreciated!

Reply With Quote
Reply

Viewing: Dev Shed ForumsMobile ProgrammingiPhone SDK Development > Help With Multiple Text Field Valdiation

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap