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?

有帮助吗?

解决方案

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
}

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top