persian date validation regex

علی ذوالفقار
1401/06/27 10:01:54 (73)
const validatePersianDate = (dateString)=>{
    var regex = /^[1-4]\d{3}\/((0[1-6]\/((3[0-1])|([1-2][0-9])|(0[1-9])))|((1[0-2]|(0[7-9]))\/(30|31|([1-2][0-9])|(0[1-9]))))$/ ; 
    return regex.test(dateString);
};

console.log(validatePersianDate('1399/01/05')); //-> true
console.log(validatePersianDate('1399/1/05')); //-> false
console.log(validatePersianDate('1399/13/05')); //-> false
console.log(validatePersianDate('1399/12/32')); //-> false
Back