Validity Checks using Clojure

Table of contents
Reading Time: 2 minutes

For putting Validation checks using Clojure code, clojure noir library checks are used.

One needs to first create a form page using basic html for placing the checks.As an Example here, I am using a registration page text boxes to put the validation checks over the required fields.

Then we move ahead by creating a register.clj file where all validations are defined under the namespace definition:

Next is to create the route that defines the register function which is called when the register page is rendered.

the above route calls the following function:

where, [id] for any number of arguments passed, (layout/render) renders with that html page where validations are required to be placed, :id-error/email-error are variables placed in the html form that will define the error block, (vali/on-error) denotes noir validation structure.

Next step is to define the errors and put checks over the required fields i.e; defining the errors for above created check blocks.

Written by 

Joseph Ross is a Principal Consultant at Knoldus Inc. having more than 10 years of experience. Joseph has a passion for identifying challenges and give impactful solutions to the clients. He is a football fan and loves to watch TV series. Joseph has a cross-functional business operations and technology consulting experience. Joseph is familiar with programming languages such as Scala, C++, Java, CSS and HTML.