From 0d2b50c9a6fa2c1dfe85d70a11673760b6d37378 Mon Sep 17 00:00:00 2001 From: David Patterson Date: Wed, 2 Mar 2016 21:48:30 -0600 Subject: [PATCH] Added remote validation and updated README accordingly --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index c4525a1..e8317d6 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,33 @@ class SSNVRule: RegexRule { } ``` +## Remote Validation + +Register field to `validator` with `remoteInfo` parameter set + +`validator.registerField(emailTextField, errorLabel: emailErrorLabel, rules: [RequiredRule(), EmailRule()], remoteInfo: (urlString: "http://localhost:8000/emails/", error: "Email already in use"))` + +Implement `ValidationDelegate`'s `remoteValidationRequest` method +```swift +func remoteValidationRequest(text: String, urlString: String, completion: (result: Bool) -> Void) { + // Add email to urlString + let newUrlString = "\(urlString)?email=\(text)" + YourNetworkingLibrary.request(.GET, newUrlString) { data -> Void in + + if data.httpResponse.statusCode == 404 { + // resource was not found, therefore the text (username, email, etc) is available + completion(result: true) + } + + if data.httpResponse.statusCode == 200 { + // resource was found, therefore the text (username, email, etc) is unavailable + completion(result: false) + } + } +// end of remoteValidationRequest method +} +``` + Credits -------