Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Refer @Bala's answer</p> <pre><code>NSString *call = @"+91-9884715715"; // Search for the "+a" starting at the end of string NSRange range = [call rangeOfString:@"+" options:NSBackwardsSearch]; // What did we find if (range.length &gt; 0) NSLog(@"Range is: %@", NSStringFromRange(range)); </code></pre> <h2>Edit</h2> <p>Refer following link: <a href="https://stackoverflow.com/questions/5765654/textfield-validation-with-regular-expression/5784131#5784131">TextField Validation With Regular Expression</a></p> <p>Change the line </p> <pre><code>- (BOOL)validateInputWithString:(NSString *)aString { NSString * const regularExpression = @"^([+]{1})([0-9]{2,6})([-]{1})([0-9]{10})$"; NSError *error = NULL; </code></pre> <p>Add the code</p> <pre><code>- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { char *x = (char*)[string UTF8String]; //NSLog(@"char index is %i",x[0]); if([string isEqualToString:@"-"] || [string isEqualToString:@"+"] || [string isEqualToString:@"0"] || [string isEqualToString:@"1"] || [string isEqualToString:@"2"] || [string isEqualToString:@"3"] || [string isEqualToString:@"4"] || [string isEqualToString:@"5"] || [string isEqualToString:@"6"] || [string isEqualToString:@"7"] || [string isEqualToString:@"8"] || [string isEqualToString:@"9"] || x[0]==0 ) { NSUInteger newLength = [textField.text length] + [string length] - range.length; return (newLength &gt; 18) ? NO : YES; } else { return NO; } } </code></pre> <h2>Edit</h2> <p>Tested with demo:</p> <pre><code> //// Button Press Event -(IBAction)Check:(id)sender{ BOOL check = [self validateInputWithString:TextField.text]; if(check == YES){ NSLog(@"Hii"); NSString *string= [NSString stringWithFormat:@"%@", TextField.text]; NSArray *first = [string componentsSeparatedByString:@"-"]; NSString *second = [first objectAtIndex:1]; NSString *third = [first objectAtIndex:0]; if([second length] &lt; 11){ NSLog(@"bang"); } else{ NSLog(@"Fault"); } if([third length] &gt; 3 || [third length] &lt; 7){ NSLog(@"Bang"); } else{ NSLog(@"fault"); } } else{ NSLog(@"FAULT"); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload