w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to use regex to validate Date and Time using Match in Jquery

I think your regexp is just treated as string. So modify them like this.

before:

var
validDate="/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/";
var validTime="/^(2[0-3]|[01][0-9]):[0-5][0-9]$/";

after:

var
validDate=/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/;
var validTime=/^(2[0-3]|[01][0-9]):[0-5][0-9]$/;




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.