Reputation: 189
Below is my code and I want to perform segue based on response string, but couldn't, can someone watch out my code and tell me what's wrong.
and when I am entering value in contact no. textfield,app is terminating with the error :
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't do regex matching on object <UITextField: 0x7faae2079980; frame = (20 353; 280 45); text = '9876543210'; clipsToBounds = YES; opaque = NO; autoresize = W+TM+BM; gestureRecognizers = <NSArray: 0x7faae2097250>; layer = <CALayer: 0x7faae2083bd0>>.'
Code I have try:
- (IBAction)Register:(id)sender {
if ((uname.text.length==0)&&(uemail.text.length==0)&&(ucontact.text.length==0)&&(upwd.text.length==0)&&(confirmpwd.text.length==0)){
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Can not Register"
message:@"All the Fields are Mandatory"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:@"Cancel", nil];
[alert show];
}
else{
NSString *emailString = uemail.text;// storing the entered email in a string.
//Regular expression to checl the email format.
NSString *emailReg = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest=[NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailReg];
if(([emailTest evaluateWithObject:emailString]!=YES)||[emailString isEqualToString:@""])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"Enter your email in [email protected] format." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
uemail.text = @"";
return;
}
}
NSString *mobile=ucontact.text;
NSString *numberRegEx = @"([0-9]{10})";
NSPredicate *numberTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", numberRegEx];
if ([numberTest evaluateWithObject:ucontact] != YES||[mobile isEqualToString:@""])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"Enter a Valid Number." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
uemail.text = @"";
return;
}
if ((upwd.text)!=(confirmpwd.text)) {
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Password Do Not Match"
message:nil
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:@"Cancel", nil];
[alert show];}
NSURL *url = [NSURL URLWithString:@"http://108.179.246.128/connectme/service/registration.php"];
NSMutableURLRequest *rq = [NSMutableURLRequest requestWithURL:url];
[rq setHTTPMethod:@"POST"];
NSString *params=[NSString stringWithFormat:@"name=%@&email=%@&mobile=%@&passwrd=%@",self->uname.text,self->uemail.text,self->ucontact.text,self->upwd.text];
NSData *postData = [params dataUsingEncoding:NSASCIIStringEncoding];
[rq setHTTPBody:postData];
NSURLResponse *response;
NSError *error;
NSData *urlData = [NSURLConnection sendSynchronousRequest:rq returningResponse:&response error:&error];
NSString *str=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding]; NSLog(@"Login response:%@",str); //getting response
// [self performSegueWithIdentifier:@"activity" sender:self];
if([str isEqual: @"Successfully Registered"])
{
[self performSegueWithIdentifier:@"login" sender:self];
}
else if([str isEqual:@"Sorry Email address already taken"])
{
UIAlertView *alertit=[[UIAlertView alloc] initWithTitle:@"Can not Register"
message:@"Email Address already Taken"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:@"Cancel", nil];
[alertit show];
}
}
Upvotes: 0
Views: 132
Reputation: 72460
For your second question that is crashing, it is because you need to pass the textField.text
not the UITextField
object. So it should be mobile
variable that contain text of textField instead of ucontact
textField object.
[numberTest evaluateWithObject:mobile]
Upvotes: 1