Skip to content

Instantly share code, notes, and snippets.

@papachan
Created September 25, 2019 15:57
Show Gist options
  • Save papachan/966610cc3dbae1e9dea902414d3ecda9 to your computer and use it in GitHub Desktop.
Save papachan/966610cc3dbae1e9dea902414d3ecda9 to your computer and use it in GitHub Desktop.
(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