Skip to content

Commit 8ec77c8

Browse files
committed
Added a couple more predicates for testing type of value
1 parent f96e59b commit 8ec77c8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/valip/predicates.clj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
form."
44
(:require [clojure.string :as string])
55
(:import
6+
[java.net URL MalformedURLException]
67
java.util.Hashtable
78
javax.naming.NamingException
89
javax.naming.directory.InitialDirContext
@@ -48,6 +49,18 @@
4849
(if-let [domain (second (re-matches #".*@(.*)" email))]
4950
(boolean (dns-lookup domain "MX"))))
5051

52+
(defn url?
53+
"Returns true if the string is a valid URL."
54+
[s]
55+
(try
56+
(URL. s) true
57+
(catch MalformedURLException _ false)))
58+
59+
(defn digits?
60+
"Returns true if a string consists only of numerical digits."
61+
[s]
62+
(boolean (re-matches #"\d+" s)))
63+
5164
(defn integer-string?
5265
"Returns true if the string represents an integer."
5366
[s]

0 commit comments

Comments
 (0)