Q:

How to remove a regex added to a textfield?

I have a specific situation in which at first I have to add a regex to my textfield and then after a while I have to remove it. I added it successfully but I dont know how to remove it. If someone can tell me how update the regex on textfield then that can also work. I have tried overriding the older regex but its not working at all. Here is the code I am having trouble with, sometimes the if condition is true and at times the control goes to the else block.
-(void)addRegexInformation{

if ([[USERDEFAULT stringForKey:USERSELECTEDLANGUAGE] isEqualToString:@"Persian"] || [[USERDEFAULT stringForKey:USERSELECTEDLANGUAGE] isEqualToString:@"Spanish"] || [[USERDEFAULT stringForKey:USERSELECTEDLANGUAGE] isEqualToString:@"German"]) {

    [emailTxtFld addRegx:REGEX_EMAIL withMsg:[UtilityHandler convertIntoSelectedLanguage:CustomLocalisedString(@"validEmail")]];

    [passwordTxtFld addRegx:REGEX_USER_NAME_LIMIT withMsg:[UtilityHandler convertIntoSelectedLanguage:CustomLocalisedString(@"enterPassMsg")]];
}
else{
    [emailTxtFld addRegx:REGEX_EMAIL withMsg:CustomLocalisedString(@"validEmail")];

    [passwordTxtFld addRegx:REGEX_USER_NAME_LIMIT withMsg:CustomLocalisedString(@"enterPassMsg")];

}

}

A:

addRegx is not built into the iOS SDK but instead is an API added by a couple different open source Text Field validators, like the one found at https://github.com/dhawaldawar/TextFieldValidator (documentation found here).
There's also a more recent (as of two years ago) version found at https://github.com/canicelebrate/AETextFieldValidator and this can be incorporated via Cocoapods.
You're not specifying which one you're using so we'll just assume AETextFieldValidator for now.
GhazalahTextFieldValidator.h
#import <UIKit/UIKit.h>
#import "AETextFieldValidator.h"

@interface GhazalahTextFieldValidator : AETextFieldValidator

@end

GhazalahTextFieldValidator.m
#import "GhazalahTextFieldValidator.h"

@interface GhazalahTextFieldValidator() {
    NSMutableArray *arrRegx;
}
@end

@implementation GhazalahTextFieldValidator

- (void)emptyRegxArray {
    [arrRegx removeAllObjects];
}

@end

Set your textfields to be these validators and you should be good to go.

