Pergunta

I want my users to be able to enter their webpage url when signing up.
Does lift have any built in support for url format validation?

Foi útil?

Solução

AFAIK, no, but you can create a simple validation rule:

import java.net.{ URL, URISyntaxException };
import scala.util.Try

def isValidUrl(url: String): Boolean = {
  Try { val link = new URL(url); true } getOrElse false
}

Outras dicas

If your users have an HTML5 browser, you can use the SHtml.url function to generate an input that is validated client-side. This relies on the HTML type="url" attribute for an input and so is only supported in more modern browsers.

There is no server-side validation baked into Lift, but you can use any number of third party ones like Apache Commons or as @flavian mentioned, you can write your own.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top