Created
March 23, 2013 15:15
-
-
Save cddr/5228055 to your computer and use it in GitHub Desktop.
Common Lisp validation syntax
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
(defclass venue (validatable) | |
((zip :col-type string :initarg :zip :accessor zip) | |
(phone :col-type string :initarg :phone :accessor phone) | |
(website :col-type (or db-null string) :initarg :website :accessor website)) | |
(:metaclass pomo:dao-class) | |
(:keys id)) | |
(defvalidators venue () | |
(website (start-with "https://")) | |
(phone (match "(\\d\\d\\d)-\\d\\d\\d-\\d\\d\\d")) | |
(zip (match "\\d\\d\\d\\d\\d"))) | |
(valid? (make-instance 'venue)) | |
=> ((WEBSITE "NIL doesn't START-WITH (https://)") | |
(PHONE "NIL doesn't MATCH ((ddd)-ddd-ddd)") (ZIP "NIL doesn't MATCH (ddddd)")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://digitalinfodigital.blogspot.com