I have a date input box in my lift application, and I want to check that a user-entered date is in correct format: dd/mm/yyyy.
How can I write a regex check for this in scala? I've looked at pattern matching examples - but that seems over-complicated.
PS: I don't have to use regex, any other alternatives are welcome!
It's a good practice to define the DateTimeFormatter
instance in an object since it's thread-safe and immutable.
object DateOfBirth{
import org.joda.time.format.DateTimeFormat
import scala.util.Try
val fmt = DateTimeFormat forPattern "MM/dd/yyyy"
def validate(date: String) = Try(fmt.parseDateTime(date)).isSuccess
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With