timo-schmid / svalidate   0.3

Website GitHub

lightweight validation for scala

Scala versions: 2.12 2.11 2.10

svalidate - lightweight validation for scala

Basic usage

import svalidate._
import svalidate.validator.NonEmptyString

case class UserData(id: Int, email: String, firstName: String, lastName: String)

val nameValidation = form[UserData](
  Validation("firstName", _.firstName, NonEmptyString),
  Validation("lastName",  _.lastName,  NonEmptyString)
)

// no errors
val jSparrow = UserData(1, "[email protected]", "Jack", "Sparrow")
val res1 = nameValidation(jSparrow)
// returns:
// Map() 

// some errors
val invalidUserData = UserData(0, "", "", "")
val res2 = nameValidation(invalidUserData)
// Map(
//   firstName -> List(The field %s must not be empty),
//   lastName -> List(The field %s must not be empty)
// )

Build-dependency

libraryDependencies ++= Seq(
  "svalidate" %% "svalidate" % "0.3"
)
resolvers += Resolver.bintrayRepo("timo-schmid", "maven")

Documentation

Read the docs

Running the tests

sbt ~test

Generating the docs

sbt tut