0

I have a form when submitted checks for null value and incorrect format of data. The issue here is even when the format is correct it throws the error. The date format i want is dd/mm/yyyy.

$("#sche_inter_form").submit(function(e){
if( ($("#inter_date").val()==="") || checkdateFormat()) {
     $("#inter_date").css({"border-bottom":" 1px solid #dd4b39"});
     e.preventDefault(e);
     }
function checkdateFormat(){
   var date = $("#inter_date").val();
   console.log(date);
   var re= new RegExp("/^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d+$/");
     var result = re.test(date);
     if (result) {
        return false;
            }
     else{
        return true;
         }
        }
2

1 Answer 1

1

Your regex is not matching a sample date like 11/11/2000.

Use this regex:

new RegExp("^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)[0-9]{2,}$")
Sign up to request clarification or add additional context in comments.

2 Comments

@NaveenKumar The /'s surrounding the regex are not required in RegExp(). See: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
But without that it throws error unexpected token caret symbol

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.