Created
September 25, 2019 15:57
-
-
Save papachan/966610cc3dbae1e9dea902414d3ecda9 to your computer and use it in GitHub Desktop.
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 clojure-app.core | |
(:require [clojure.spec.alpha :as s])) | |
(def email-regex #"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,63}$") | |
(s/def ::email-type (s/and string? #(re-matches email-regex %))) | |
(s/def ::acctid int?) | |
(s/def ::first-name string?) | |
(s/def ::last-name string?) | |
(s/def ::email ::email-type) | |
(s/def ::person (s/keys :req [::first-name ::last-name ::email] | |
:opt [::phone])) | |
(s/valid? ::person | |
{::first-name "Bugs" | |
::last-name "Bunny" | |
::email "bugs@example.com"}) | |
;; => true | |
(s/explain ::person | |
{::first-name "Bugs"}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment