Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex for Date and time picker javascript

I was trying to find regex for a date and time picker in JavaScript

https://i.sstatic.net/KQWgO.png

which format is hh/mm ampm and dd/mm/yyyy hh/mm ampm.

I tried ([0-3][0-9])([0][1-9]|[1][0-2])-\d{4} ( ([0-1][0-9]|[2][0-4]):[0-5][0-9]) but doesnt seem to work cuz / apparently is not a normal simbol.

What is the correct regular expresion? RegEx has always been hard for me

like image 872
Delicia Avatar asked Nov 21 '25 08:11

Delicia


1 Answers

If those are the standard <input type="datetime" /> and variants thereof, then you should really do some basic debugging.

console.log(datetimeInput.value);
// 2020-08-17 23:33:05

Date and time inputs are displayed in the user's local format, but they are internally stored in the correct format. Furthermore, they are validated automatically by the browser, so there should be no need whatsoever to run a regex over them.

like image 151
Niet the Dark Absol Avatar answered Nov 22 '25 22:11

Niet the Dark Absol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!