Design a site like this with
Get started

Function to validate Date of Birth using Regex

Regex to validate date of birth


In Jquery

var checkDOB = function () {   
   var regexp = new RegExp( '^(0[1-9]|1[012])[/](0[1-9]|[12][0-9]|3[01])[/](19|20)\\d\\d$');
   var check = $("#AddDateOfBirth").val();
   if (!regexp.test(check)) {

       alert('Invalid Format. Please Enter: dd/mm/yyyy');
       $('#AddDateOfBirth').css('border-color', 'red');
       return false;

   else {
       $('#AddDateOfBirth').css('border-color', 'green');
       return true;


@Html.TextBox("AddDateOfBirth", null, new { @class = "form-control text-box", @placeholder = "dd/mm/yyyy", @onchange = "checkDOB()" })


This regex will validate date of birth by allowing you to enter the date of birth in this format dd/mm/yyyy only. Invalid input (not in the format dd/mm/yyyy) will return false and make the borders of text-box red.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Create a free website or blog at

Up ↑

%d bloggers like this: