Results 1 to 1 of 1
Discuss Help with Multiple Text Field Validation at the iPhone Developer Exchange - Hackint0sh.org; I have five fields I need to validate, as different fields require a different range ...
  1. #1
    Newbie Array

    Join Date
    Jan 2010
    Posts
    1
    Post Thanks / Like
    Downloads
    0
    Uploads
    0
    Rep Power
    0

    Default Help with Multiple Text Field Validation

    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)
    2010-01-12_1258

    Any advice would be greatly appreciated!
    Last edited by zacharyrs; 01-12-2010 at 08:10 PM.



 

 

Similar Threads

  1. [NCK] validation algorithm public
    By toruonu in forum iPhone "2G" (Rev. 1)
    Replies: 195
    Last Post: 01-17-2012, 01:18 PM
  2. Looking for Volunteers for Product Validation
    By mafili in forum iPhone Developer Exchange
    Replies: 0
    Last Post: 06-01-2011, 04:39 AM
  3. [Update] iPod touch $20 validation on reload
    By juliangall in forum iPod Touch 1G
    Replies: 8
    Last Post: 01-21-2008, 03:53 PM
  4. Text Message to multiple recepients?
    By humblehyper in forum General
    Replies: 1
    Last Post: 09-16-2007, 07:42 AM
  5. Need Field Test.app
    By wraithfive in forum Free Toolchain Software (Cydia App's)
    Replies: 4
    Last Post: 08-23-2007, 10:55 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Powered by vBulletin®
Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.
Search Engine Friendly URLs by vBSEO
(c) 2006-2012 Hackint0sh.org
All times are GMT +2. The time now is 12:14 PM.
twitter, follow us!