/ Published in: JavaScript

This is used to validate a date in a specific format. The code example is to validate whether it is a valid dd/MM/yyyy Date Format.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function ValidateDateFormat(input) { var dateString = input.value; var regex = /(((0[1-9]|1[0-2])\/(0|1)[0-9]|2[0-9]|3[0-1])\/((19|20)\d\d))$/; //Check whether valid dd/MM/yyyy Date Format. if (regex.test(dateString) || dateString.length == 0) { ShowHideError("none"); } else { ShowHideError("block"); input.focus(); input.select(); } };
Comments
