[Gambas-user] How to verify a date like dd/mm/yyyy?

Benoit Minisini gambas at ...1...
Fri Mar 21 13:19:20 CET 2008


On vendredi 21 mars 2008, andy2 wrote:
> in Php i found the following script. My problem is to replicate the ereg
> function.
>
> FUNCTION ControlloData($data){
>   If(!ereg("^[0-9]{2}/[0-9]{2}/[0-9]{4}$", $data)){
>     RETURN FALSE;
>   } ELSE {
>     $arrayData = explode("/", $data);
>     $Giorno = $arrayData[0];
>     $Mese = $arrayData[1];
>     $Anno = $arrayData[2];
>     If(!checkdate($Mese, $Giorno, $Anno)){
>       RETURN FALSE;
>     } ELSE {
>       RETURN TRUE;
>     }
>   }
> }
>

What do you need to do exactly?

If you want to know if a string can be interpreted as a date, then you must do 
something like that:

DIM vDate AS Variant
DIM sStr AS String

vDate = Val(sStr)
IF IsDate(vDate) THEN
  ' OK, I got a date
ELSE
  ' Bad, I didn't go a date
ENDIF

Regards,

-- 
Benoit Minisini




More information about the User mailing list