Question

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?

Était-ce utile?

La solution

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
}

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top