If it fails to convert String to Date then it returns null.
2) you can prevent the Parse Exception using the often overlooked other parse method, that takes a Parse Position.
My earlier post on how to validate email address, SSN and phone number validation using Java regex still attracts a lot of visitors.
Catch parse exception to test if validation failed. Loop the above process for the set of formats against which the validation needs to be performed.
* In this scenario, there is no fixed format against which the validation is supposed to be done.
First I’ll show you how to validate date using java regex in US format and later I’ll show you how that same logic can be applied to validate date in English format (used in most countries outside North America).