ios - how to eliminate the occurence of a certain character from a textfield and have it present only at the prefix -


i have uitextfield lets user type in phone number want test uitextfield such user shouldnt enter "+" anywhere else in textfield apart prefix.

is there way can test condition? have done far,please note fourth textfield using tag distinguish other textfields

- (bool)textfield:(uitextfield *)textfield shouldchangecharactersinrange:(nsrange)range replacementstring:(nsstring *)string {    if (textfield.tag==3) {     static nscharacterset *charset = nil;           if(!charset) {                charset = [[nscharacterset charactersetwithcharactersinstring:@"0123456789+"] invertedset];           }   nsrange location = [string rangeofcharacterfromset:charset];              return (location.location == nsnotfound);  // delete characters backspace     if ([string isequaltostring:@""])     {         return yes;     }         } return yes;  } 

the above condition allows numbers , "+" symbol thanks

try wont take + anywhere else except first position ,

 - (bool)textfield:(uitextfield *)textfield shouldchangecharactersinrange:(nsrange)range replacementstring:(nsstring *)string {    if (textfield.tag==3)    {         if([textfield.text length]>1){             if([string isequaltostring:@"+"])             {                 return no;             }             else              {                 return yes;             }         }         return yes;     } } 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -