This article provides a regular expression to verify whether a date is a regular date format. The first is a normal date verification, which is passed safely. The date format in section 2 is incorrect, so the output date is invalid. This article provides a regular expression to verify whether a date is a regular date format. The first is a normal date verification, which is passed safely. The date format in section 2 is incorrect, so the output date is invalid.
Script ec (2); script
| The Code is as follows: |
|
$ Date = "2003-01-31 ";
If (ereg ("([0-9] {4})-([0-9] {1, 2})-([0-9] {1, 2 })", $ date, $ regs )){
Echo "$ regs [3]/$ regs [2]/$ regs [1]
";
Echo "$ regs [0]
";
Echo "$ regs [1]-$ regs [2]-$ regs [3 ";
} Else {
Echo "invalid date Format: $ date ";
} |
// Date instance 2
| The Code is as follows: |
|
$ Date = "2020.01-31 ";
If (ereg ("([0-9] {4})-([0-9] {1, 2})-([0-9] {1, 2 })", $ date, $ regs )){
Echo "$ regs [3]/$ regs [2]/$ regs [1]
";
Echo "$ regs [0]
";
Echo "$ regs [1]-$ regs [2]-$ regs [3 ";
} Else {
Echo "invalid date Format: $ date ";
} |
?>