Valid date format validation using Javascript (Ex: dd/mm/yyyy) using regular expression

Before this you may need, require field validation using javascript.For date format validation we are using regular expression. If we enter any date in text box, textbox will accept date which are in dd/mm/yyyy format.

If you have any queries on this. please ask in comments.

   
<html>
<head>
    <title></title>
    <script type="text/javascript">
        function ValidateForm() {
            var txtDate = document.getElementById("txtDate").value;
            var regularExpression = /^\d{1,2}\/\d{1,2}\/\d{4}$/; ;
            if (!txtDate.match(regularExpression)) {
                alert("Please enter date format.Ex: 05/05/2012");            
            }
        }
    </script>
</head>
<body>
Date: <input type="text" id="txtDate" /><br />
<br />
<input type='button' value="validate" onclick="ValidateForm();" />

</body>
</html>


If you have any queries or suggestions, please feel free to ask in comments section.
Share this post :

Post a Comment

Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.

 
Support : Ranga Rajesh Kumar
Copyright © 2012. ASP.NET Examples - All Rights Reserved
Site Designed by Ranga Rajesh Kumar