Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend the RequiredRule Class #136

Open
sumitjain7 opened this issue Aug 17, 2016 · 1 comment
Open

Extend the RequiredRule Class #136

sumitjain7 opened this issue Aug 17, 2016 · 1 comment

Comments

@sumitjain7
Copy link

I want to change the validate(value:String) method in RequiredRule.swift class.
It should first trim all whitespaces then should check for isEmpty.

For this I want to create a String class extension like this:

extension String
{
    func trim()->String
    {
        return self.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet());
    }
}

and then change the validate method like this:

public func validate(value: String) -> Bool { return !(value.trim().isEmpty) }

Suggest me how to do this.

@dimohamdy
Copy link

@sumitjain7 you should change validationText in in Validatable.swift

extension UITextView: Validatable {
    
    public var validationText: String {
        
        if let text = text {
            text.trim()
        }
        return ""
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants