All Downloads are FREE. Search and download functionalities are using the official Maven repository.

xitrum.validator.Validator.scala Maven / Gradle / Ivy

There is a newer version: 3.28.18
Show newest version
package xitrum.validator

import xitrum.exception.InvalidInput

trait Validator[T] {
  /** Returns false if validation fails, otherwise true. */
  def check(value: T): Boolean

  /** Returns Some(error message) if validation fails, otherwise None. */
  def message(name: String, value: T): Option[String]

  /** Throws exception InvalidInput(error message) if validation fails. */
  def exception(name: String, value: T) {
    message(name, value).foreach { message => throw new InvalidInput(message) }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy