<!Doctype Html>
<Html>
<Body>
<input type="text" id="bday"/>
<button onclick="ValiDate()">Validate</button>
<script>
function ValiDate()
{
if (ValiBday == true)
{
alert("true");
}
else
{
alert("false");
}
}
function ValiBday()
{
//I get the value of the input element
var inputValue=document.getElementById('bday').value;
// I create a new var with Regex rule to get only numbers
var pattern =/^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/;
//I set a flag boolen to test if the inputValue has RegEx format
var flag=pattern.test(inputValue);
//I create an if condition to check if flag is true or false
if(flag===false){
ValiBday = "false";
return false;
}
//I parse the value to date object time in unix format (ms)
var birthday =Date.parse(document.getElementById('bday').value);
//I check the condition
if(isNaN(birthday))
{
ValiBday = "false";
return false;
}
ValiBday = "true";
}
</script>
</Body>
</Html>
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.