Here you can find the source of isDate(String s)
public static boolean isDate(String s)
//package com.java2s; //License from project: Open Source License import java.text.ParsePosition; import java.text.SimpleDateFormat; public class Main { public static boolean isDate(String s) { if (s != null) { if (s.matches("^\\d{4}([/.-])\\d{2}\\1\\d{2}$")) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); sdf.setLenient(false);/*w w w . j av a2 s . c o m*/ return sdf.parse(s.replaceAll("[/.]", "-"), new ParsePosition(0)) != null; } else if (s.matches("^\\d{2}([/.-])\\d{2}\\1\\d{4}$")) { SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy"); sdf.setLenient(false); return sdf.parse(s.replaceAll("[/.]", "-"), new ParsePosition(0)) != null; } } return false; } }