Multiple if-else conditions in ios [closed] - ios

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I have a sign-up view controller that contains multiple text fields to register the user.
I need to validate all the text fields such as not empty, valid email, username, password etc. and display the alert message for all different condition.
Now I following the approach as:
if (condition) {
if (condition) {
if (condition) {
} else {
[alert show];
}
} else {
[alert show];
}
} else {
[alert show];
}
I know this is not the best approach. So guys please suggest an appropriate way to do that task.
Thanks,

Multiple If else Condition
NSString *emailRegEx = #"[A-Z0-9a-z._%+-]+#[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:#"SELF MATCHES %#", emailRegEx];
NSString *mobileRegex = #"[0-9]{6,14}$";
NSPredicate *mobileTest = [NSPredicate predicateWithFormat:#"SELF MATCHES %#", mobileRegex]
if (txtName.text.length == 0)
{
[[[UIAlertView alloc]initWithTitle:#"Alert" message:#"Please Enter Name" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil] show];
}
else if (txtMobile.text.length == 0)
{
[[[UIAlertView alloc]initWithTitle:#"Alert" message:#"Please Enter Mobile Number" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil] show];
}
else if ([mobileTest evaluateWithObject:txtMobile.text] == NO)
{
[[[UIAlertView alloc]initWithTitle:#"Alert" message:#"Please Enter valid Mobile Number" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil] show];
}
else if (txtMobile.text.length < 10)
{
[[[UIAlertView alloc]initWithTitle:#"Alert" message:#"Please Enter valid Phone Number" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil] show];
}
else if (txtMobile.text.length > 10)
{
[[[UIAlertView alloc]initWithTitle:#"Alert" message:#"Please Enter valid Phone Number" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil] show];
}
else if (txtEmail.text.length == 0)
{
[[[UIAlertView alloc]initWithTitle:#"Alert" message:#"Please Enter Email" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil] show];
}
else if ([emailTest evaluateWithObject:txtEmail.text] == NO)
{
[[[UIAlertView alloc]initWithTitle:#"Alert" message:#"Please Enter valid Email" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil] show];
}
else
{
//success Code
}

Here isAllFieldsAreValid() will validate all the fields you can add all the validation here.
showAlert is a method to show alert about error.
allTrim() is a macro that will trim whitespace.
- (BOOL)isAllFieldsAreValid {
//here only empty string is checked you can add other if-else to validate email, phno, etc.
if ([allTrim(self.txtFname.text) isEqualToString:#""]) {
[self showAlert:#"Please enter first name."];
return false;
} else if ([allTrim(self.txtLname.text) isEqualToString:#""]) {
[self showAlert:#"Please enter last name."];
return false;
} else if ([allTrim(self.txtEmail_SignUp.text) isEqualToString:#""]) {
[self showAlert:#"Please enter email id."];
return false;
} else if ([allTrim(self.txtPassword_SignUp.text) isEqualToString:#""]) {
[self showAlert:#"Please enter password."];
return false;
}
return true;
}
You can call this on button click and upon true and false you can take action.
- (IBAction)buttonTappedInLoginView:(UIButton *)sender {
if ([self isAllFieldsAreValid]) {
// do stuff
}
}

Use this code,
if (firstnametf.text.length==0 || lastnametf.text.length==0 || emailtf.text.length==0 || myimageView.image == nil || commenttf.text.length==0 || [commenttf.text isEqualToString:#"Comment"])
{
[self validatetextfield];
}
else if (![emailtf.text isEqualToString:#""])
{
NSString *emailRegEx = #"[A-Z0-9a-z._%+-]+#[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:#"SELF MATCHES %#", emailRegEx];
//Valid email address
if ([emailTest evaluateWithObject:emailtf.text] == YES)
{
//All conditions are checked, you will set the function
}
else if ()
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Test!" message:#"Please Enter Valid Email Address. \nex. fdsjfkd#mail.com" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
}
}
Method:
-(void) validatetextfield
{
if (firstnametf.text.length==0) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Firstname Field Empty!" message:#"Please Enter the Valid Details" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[firstnametf becomeFirstResponder];
}
else if (lastnametf.text.length==0)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Lastname Field Empty!" message:#"Please Enter the Valid Details" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[lastnametf becomeFirstResponder];
}
else if (emailtf.text.length==0)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Email Field Empty!" message:#"Please Enter the Valid Details" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[emailtf becomeFirstResponder];
}
else if(commenttf.text.length==0)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Comment Field Empty!" message:#"Please Enter the Valid Details" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[commenttf becomeFirstResponder];
}
else if ([commenttf.text isEqualToString:#"Comment"])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Comment Field Empty!" message:#"Please Enter the Valid Details" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[commenttf becomeFirstResponder];
}
else if (myimageView.image == nil)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Image not Upload!" message:#"Please Upload Image" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
}
Change the Alert condition, hope its helpful

Related

I am trying to call an UIAlertView method for particular UIButton like UpdateEmail or ForgotPassword but properly call i am use this code

I am using this code for Update Email Address and Forgot Password but their is a problem when I click on 'ForgotPassword' button it's work properly but when I click on 'UpdateEmail' button it not work properly it call the UIAlert for 'ForgotPassword' button and I am trying to call" else if (self.ForgotPassword.tag == 1) part of -(Void)alertView " for when I press 'UpdateEmail' UIButton.
//Forgot method for ForgotPassword
-(IBAction)ForgotPassword:(id)sender
{
UIAlertView * forgotPassword=[[UIAlertView alloc] initWithTitle:#"Forgot Password" message:#"Please enter your email id" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
forgotPassword.alertViewStyle=UIAlertViewStylePlainTextInput;
[forgotPassword textFieldAtIndex:0].delegate=self;
[forgotPassword show];
}
//Method for Update Email Address
-(IBAction)UpdateEmail:(id)sender
{
if ([PFUser currentUser])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Update Email"
message:#"Enter Your Email Address"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Ok",nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];
}
else
{
UIAlertView *myAlert1 = [[UIAlertView alloc]
initWithTitle:#"Please First Loginig"
message:#"Please First Loging"
delegate:nil
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Ok",nil];
[myAlert1 show];
}
}
// Method for Alert View
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
self.ForgotPassword.tag=0;
self.UpdateEmail.tag=1;
if (self.ForgotPassword.tag == 0){
if(buttonIndex ==1){
NSLog(#"ok button clicked in forgot password alert view");
NSString *femailId=[alertView textFieldAtIndex:0].text;
if ([femailId isEqualToString:#""]){
UIAlertView *display;
display=[[UIAlertView alloc] initWithTitle:#"Email" message:#"Please enter password for resetting password" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles: nil];
[display show];
}else{
[PFUser requestPasswordResetForEmailInBackground:femailId block:^(BOOL succeeded, NSError *error){
UIAlertView *display;
if(succeeded){
display=[[UIAlertView alloc] initWithTitle:#"Password email" message:#"Please check your email for resetting the password" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles: nil];
}else{
display=[[UIAlertView alloc] initWithTitle:#"Email" message:#"Email doesn't exists in our database" delegate:nil cancelButtonTitle:#"Cancel" otherButtonTitles: nil];
}
[display show];
}];
}
}
}else if (self.ForgotPassword.tag == 1){
PFUser *user = [PFUser currentUser];
user[#"email"] = [alertView textFieldAtIndex:0].text;
[user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error){
if (succeeded){
UIAlertView *myAlert1 = [[UIAlertView alloc]
initWithTitle:#"Email Upadated!"
message:#"your Email is Updated"
delegate:nil
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Ok",nil];
[myAlert1 show];
//NSLog(#"Success");
}else{
UIAlertView *myAlert1 = [[UIAlertView alloc]
initWithTitle:#"Email is NOT Update"
message:#"Email is alredy registred"
delegate:nil
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Ok",nil];
[myAlert1 show];
NSLog(#"Error");
}
}];
}
}
You need to give tag to your two different UIAlertView like below.
-(IBAction)ForgotPassword:(id)sender
{
UIAlertView * forgotPassword=[[UIAlertView alloc] initWithTitle:#"Forgot Password" message:#"Please enter your email id" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
forgotPassword.alertViewStyle=UIAlertViewStylePlainTextInput;
[forgotPassword textFieldAtIndex:0].delegate=self;
[forgotPassword show];
forgotPassword.tag = 0; //// Here for forgot password
}
-(IBAction)UpdateEmail:(id)sender
{
if ([PFUser currentUser])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Update Email"
message:#"Enter Your Email Address"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Ok",nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];
alert.tag =1; ///Here for email update
}
}
Then, in -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex, you can detect which alertView's button was clicked.
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
{
if(alertView.tag == 0) /// Because we assigned forgotPassword.tag = 0; above for forgotPassword
{
if(buttonIndex == YOUR_DESIRED_BUTTON_INDEX)
{
///Your code for Forgot Password.
}
}
else if(alertView.tag ==1) /// Because we assigned alert.tag = 1; above for update email
{
if(buttonIndex == YOUR_DESIRED_BUTTON_INDEX)
{
///Your code for Update Email.
}
}
}

Parse for iOS using reset parse function

I want to implement a function that allows users to reset their password. I already created a button that displays an alert view and asks for their email, but when I tap ok, it doesn't send an email.
What can I do?
-(IBAction)forget:(id)sender {
[PFUser requestPasswordResetForEmailInBackground:#"email#example.com"];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Email Address" message:#"Enter the email for your account:" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[alertView show];
}
- (IBAction)forget:(id)sender {
[self getEmail];
}
- (void)getEmail {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Email Address" message:#"Enter the email for your account:" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[alertView show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex != [alertView cancelButtonIndex]) {
UITextField *emailTextField = [alertView textFieldAtIndex:0];
[self sendEmail:emailTextField.text];
}
}
- (void)sendEmail:(NSString *)email{
[PFUser requestPasswordResetForEmailInBackground:email];
}

Checking to see if textfields are filled out

In my Calorie Tracker App, I have two textfields. One is for the name of the food, and the other is for the amount of calories.To check and see if they are filled I wrote the following code:
if([foodString isEqual: #" "])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Warning!" message:#"You have not entered the name of the meal!" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
else if([self.amountText isEqual: #" "])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Warning!" message:#"You have not enteted the amount of calories!" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
else if([self.amountText isEqual:#" "] && [foodString isEqual:#" "])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Warning!" message:#"You haven't entered anything!" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
So for the one where the amountText textfield isn't filled out, but the nameOfFood is filled out, there is an alert. For the rest however, there is no alert. If anyone could provide the proper syntax for checking to see if my textfields are being filled out properly, it would be much appreciated.
Remember, my first textfield is a string value, and the other is an integer value.
Thanks in advance.

iOS Form Validation Error via if-else Condition Does Not Work Properly

I've written a simple app which validates user input (whether NULL or longer than a define length). It should return validation error messages when validation fails and otherwise, redirect to another page.
However, the app only returns the messge for the first condition (Username is Empty) for all scenarions. (Such as username is filled and password is empty, etc.)
m file:
- (IBAction)doLogin {
if(uname.text==NULL) {
UIAlertView *err1 = [[UIAlertView alloc]
initWithTitle:#"Required field!" message:#"Username is empty." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[err1 show];
NSLog(#"%#",uname.text);
}
else if(passw.text==NULL) {
UIAlertView *err2 = [[UIAlertView alloc]
initWithTitle:#"Required field!" message:#"Password is empty." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[err2 show];
NSLog(#"%#",passw.text);
}
else if (uname.text.length < 6)
{
UIAlertView *err3 = [[UIAlertView alloc]
initWithTitle:#"Invalid!" message:#"Enter a username longer than 6 chars." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[err3 show];
NSLog(#"%#",uname.text);
}
else if (uname.text.length < 8)
{
UIAlertView *err4 = [[UIAlertView alloc]
initWithTitle:#"Invalid!" message:#"Enter a password longer than 8 chars." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[err4 show];
NSLog(#"%#",uname.text);
}
else {
/*UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"" message:#"Thank you" delegate:self cancelButtonTitle:#"Close" otherButtonTitles:#"OK", nil];
[alert show];*/
UIViewController* flipViewController = [[UIViewController alloc] initWithNibName:#"flip" bundle:[NSBundle mainBundle]];
[self.view addSubview:flipViewController.view];
}
An alternative to karthika (but using similar structure) this will provide feedback on the entire form in a single message. Perhaps a little more user friendly and certainly reduces negative user interaction.
-(BOOL)isFormDataValid{
NSMutableArray *errorMessages = [[NSMutableArray alloc] init];
if([self.emailTextField.text isEqualToString:#""])
{
[errorMessages addObject:NSLocalizedString(#"Please enter email",nil)];
}
if([self.passwordTextField.text isEqualToString:#""])
{
[errorMessages addObject:NSLocalizedString(#"Please enter password",nil)];
}
if ([errorMessages count]) {
NSString * msgs = [errorMessages componentsJoinedByString:#"\n"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"Whoops!",nil) message:msgs delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return NO;
} else {
return YES;
}
}
-(BOOL)isFormDataValid{
NSString *errorMessage = nil;
UITextField *errorField;
if([nameTextField.text isEqualToString:#""])
{
errorMessage = #"Please enter username";
errorField = nameTextField;
}
else if([[nameTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0)
{
errorMessage = #"white spaces not allowed";
errorField = nameTextField;
}
else if([passwordTextField.text isEqualToString:#""])
{
errorMessage = #"Please enter password";
errorField = passwordTextField;
}
else if([[passwordTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0)
{
errorMessage = #"white spaces not allowed";
errorField = passwordTextField;
}
if (errorMessage) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Failed!" message:errorMessage delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
[errorField becomeFirstResponder];
return NO;
}else{
return YES;
}
}
Apart from the fact that you do
else if (uname.text.length < 8)
{
UIAlertView *err4 = [[UIAlertView alloc]
initWithTitle:#"Invalid!" message:#"Enter a password longer than 8 chars." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[err4 show];
NSLog(#"%#",uname.text);
}
instead of
else if (passw.text.length < 8)
{
UIAlertView *err4 = [[UIAlertView alloc]
initWithTitle:#"Invalid!" message:#"Enter a password longer than 8 chars." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[err4 show];
NSLog(#"%#",passw.text);
}
Your code should work just fine.
Also, bear in mind that a text field's text won't be nil, it will just be an empty string (lenght == 0), unless you explicitly set it to nil.

validate multi uitextfield

I use this code to check if text fields are empty or not. The first time, it will work, but when I change the text field values, the alert does not works.
-(void)sendclick {
NSString *msg;
if(firstnametextfield.text==NULL) {
msg=#"enter first name";
NSLog(#"%#",firstnametextfield.text);
}
else if(lastnametextfield.text==NULL) {
msg=#"enter last name";
NSLog(#"%#",lastnametextfield.text);
}
else if(emailtextfield.text==NULL) {
msg=#"enter email address";
NSLog(#"%#",emailtextfield.text);
}
else if(companytextfield.text==NULL) {
msg=#"enter company name";
NSLog(#"%#",companytextfield.text);
}
else if(phonetextfield.text==NULL) {
msg=#"enter phone numper";
NSLog(#"%#",phonetextfield.text);
}
else {
msg=#"register success fully";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:msg delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[alert show];
[alert release];
}
}
There are a couple of things to consider about this code:
As others have pointed out, this is not the correct way to check for an empty string.
a. First, if you do want to check for a string that is not allocated, you should be checking for nil and not NULL.
b. Secondly, the string could also be allocated, but have no characters, so you should check to see if it is an empty string as well.
c. Note that you typically want to check BOTH of those conditions, and do the same thing, because, usually, there is no difference between a string that is nil and one that is empty as far as the business logic is concerned.
d. The easiest way to do this is to simply check the length of the string. This works, because if a message is sent to a nil object, it will return 0, and if it is an actual string with no characters, it will also return 0.
Therefore, a check similar to this would work instead:
if([firstnametextfield.text length] == 0)
You typically do not want to check the value of a text field directly like this for form validation. This is because, under certain situations (like when a text field is in a table view cell and scrolls off of the screen) the text field is not available and you won't have access to the data stored in the text field.
Instead, you should collect the text immediately after it is entered by setting the delegate of the text field to your view controller and implementing the following function:
- (void)textFieldDidEndEditing:(UITextField *)textField {
if (textField == firstnametextfield) {
// Store the first name in a property, or array, or something.
}
}
Then, when you are ready to validate the entered information, check the values that you have stored instead of the actual text field values themselves, using the technique from #1 above.
You shouldn't compare the text field value with NULL. Rather, compare it with #"". You can also trim whitespace characters too:
[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
- (BOOL)isEmptyOrNull:(NSString*)string {
if (string) {
if ([string isEqualToString:#""]) {
return YES;
}
return NO;
}
return YES;
}
-(void)sendclick {
NSString *msg;
if([self isEmptyOrNull:firstnametextfield.text]) {
msg=#"enter first name";
NSLog(#"%#",firstnametextfield.text);
}
.....
.....
.....
Try using
if([lastnameTextField.text isEqualToString:#""])
{
msg = #"Enter last name";
NSLog(#"%#",lastnametextfield.text);
}
This is how you check if a NSString is empty or not.
You can't compare string objects using the == or != operators. So here is the correct one:
-(void)sendclick
{
NSString *msg;
if([firstnametextfield.text isEqualToString:#""])
{
msg=#"enter first name";
NSLog(#"%#",firstnametextfield.text);
}
else
if([lastnametextfield.text isEqualToString:#""])
{
msg=#"enter last name";
NSLog(#"%#",lastnametextfield.text);
}
else if([emailtextfield.text isEqualToString:#""])
{
msg=#"enter email address";
NSLog(#"%#",emailtextfield.text);
}
else if([companytextfield.text isEqualToString:#""])
{
msg=#"enter company name";
NSLog(#"%#",companytextfield.text);
}
else if([phonetextfield.text isEqualToString:#""])
{
msg=#"enter phone numper";
NSLog(#"%#",phonetextfield.text);
}
else
{
msg=#"register success fully";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:msg delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[alert show];
[alert release];
}
}
I hope that helps you.
-(void)sendclick
{
if ([self ControlValidation]==YES)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Sucess" message:#"Registration done successfully" delegate: nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
}
-(BOOL)ControlValidation
{
if ([self isEmpty:firstnametextfield.text ]==YES)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"First Name is empty" delegate: nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return NO;
}
if ([self isEmpty:lasttnametextfield.text ]==YES)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"Last Name is empty" delegate: nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return NO;
}
return YES;
}
-(BOOL)isEmpty:(NSString *)str
{
if (str == nil || str == (id)[NSNull null] || [[NSString stringWithFormat:#"%#",str] length] == 0 || [[[NSString stringWithFormat:#"%#",str] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length] == 0)
{
return YES;
}
return NO;
}
-(void)validateTextFields
{
if ([self Validation]==YES)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Sucess" message:#"Registration done successfully" delegate: nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
}
-(BOOL)Validation
{
if ([self isEmpty:firstnametextfield.text ]==YES)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"First Name is empty" delegate: nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return NO;
}
if ([self isEmpty:lasttnametextfield.text ]==YES)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"Last Name is empty" delegate: nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return NO;
}
if ([self isEmpty:Usernametextfield.text ]==YES)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"First Name is empty" delegate: nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return NO;
}
if ([self isEmpty:phonetextfield.text ]==YES)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"Last Name is empty" delegate: nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return NO;
if ([self isEmpty:emailtextfield.text ]==YES)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"First Name is empty" delegate: nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return NO;
}
if ([self isEmpty:passwordtextfield.text ]==YES)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"Last Name is empty" delegate: nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return NO;
}
}
return YES;
}
-(BOOL)isEmpty:(NSString *)str
{
if (str == nil || str == (id)[NSNull null] || [[NSString stringWithFormat:#"%#",str] length] == 0 || [[[NSString stringWithFormat:#"%#",str] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length] == 0)
{
return YES;
}

Resources