Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Scala Input Validator with quite readable DSL
Branch: develop

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


Important Notice

inputvalidator is already in maintenance mode. So only bug fixes will be released and new features won't be implemented.

Now I'm working harder on skinny-validator (it's a successor of inputvalidator and some APIs are refactored). skinny-validator is a part of skinny-framework but it doesn't depend on skinny. You can use skinny-validator anywhere as same as well as inputvalidator.

Scala Input Validator with quite readable DSL

libraryDependencies += "com.github.seratch" %% "inputvalidator" % "[1.0,)"

Use as follows:

import inputvalidator._

case class Registration(id: Int, firstName: String, lastName: Option[String], gender: String)

val validator = Validator {
  input("id" -> 12345) is required & maxLength(4), // 1 error
  input("first_name" -> "") is notNull & minLength(3), // 1 error
  input("last_name" -> "Kaz") is checkAll(minLength(5), numeric), // 2 errors
  input("gender" -> "male") is notEmpty


val res: String = validator.success {
  inputs => inputs.string("first_name")
}.failure {
  (inputs, errors) => "Failed! : " + errors

val form = { inputs => 
    id        ="id"),
    firstName = inputs.string("first_name"),
    lastName  = inputs.stringOpt("last_name"),
    gender    = inputs.string("gender")

if (form.hasErrors) {
} else {
  val registration = form.get

Accepting Map value is also simple:

val params: Map[String, Any] = request.getParameterMap()

val v = Validator(params)(
  inputKey("password") is required,
  inputKey("newPassword") is (required and minLength(6)),
  inputKey("reNewPassword") is (required and minLength(6)),
  input("pair" -> (params.get("newPassword"), params.get("reNewPassword"))) are same

Built-in Validations

See the following source code:

Your pull requests are always welcome.

Easily Extendable

If you need to add validations, it's quite simple.

Just add new class which extends inputvalidator.ValidationRule as follows:

object authenticated extends ValidationRule {
  def name = "authenticated"
  def isValid(v: Any) = {
    val (username, password) = v.asInstanceOf[(String, String)]
    UserService.authenticate(username, password).isDefined

val v = Valdiator(
  input("username" -> username) is required,
  input("passowrd" -> password) is required,
  input("login" -> (username, password)) is authenticated

Message Binding

Supports the standard way to use

post("login") {
    input("username" -> username) is required,
    input("passowrd" -> password) is required,
    input("login" -> (username, password)) is authenticated
  ).success { inputs =>
    respond(status = 200, body = render("completed.ssp"))
  }.failure { (inputs, errors) =>
      status = 400, 
      body = render("input.ssp",
        "useraname" -> inputs.get("username"),
        "password" -> inputs.get("password"),
        "errors" -> inputs.keys.flatMap { key =>
          errors.get(key).map { error =>
            Messages.get(key =, params = key :: error.messageParams.toList).getOrElse(

Do the Same Everywhere

Furthermore, this library does not depend on any other components. So you can do the same everywhere.

Please see the following examples.

  • Play framework 2.x Scala

  • Scalatra

  • Circumflex


Copyright 2013 Kazuhiro Sera

Apache License, Version 2.0

Something went wrong with that request. Please try again.