Last active
August 29, 2015 14:10
-
-
Save ryanbaldwin/13c75684d5f54b9690b4 to your computer and use it in GitHub Desktop.
hipstr.validators.user-validator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns hipstr.validators.user-validator | |
(:require [noir.validation :as v] | |
[validateur.validation :refer :all])) | |
(defn validate-signup [signup] | |
"Validates teh incoming map of values from our signup form, | |
and returns a set of error messages for any invalid key. | |
Expects signup to have :username, :email, and :password." | |
(let [v (validation-set | |
(presence-of #{:email :password} | |
:message "is a required field.") | |
(format-of :username | |
:format #"^[a-zA-Z0-9_]*$" | |
:message "Only letters, numbers, and underscores allowed." | |
:blank-message "is a required field") | |
(length-of :password | |
:within (range 8 101) | |
:message-fn (fn [type m attribute & args] | |
(if (= type :blank) | |
"is a required field" | |
"Password must be between 8 and 100 characters long."))) | |
(validate-with-predicate :email | |
#(v/is-email? (:email %)) | |
:message-fn (fn [validation-map] | |
(if (v/has-value? (:email validation-map)) | |
"the email's format is incorrect" | |
"is a required field"))))] | |
(v signup))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment