Simpel validering af dato-streng

Halløjsa,

Jeg har lavet en lille funktion, der kan validere om en dato er korrekt eller ej i PHP.
Valideringen kræver at datoen er i følgende format dd-mm-åå, dvs. f.eks. 10-01-86.

function validateDate($date)
{
    if (preg_match("/^([0-9]{2})-([0-9]{2})-([0-9]{2})$/", $date, $parts))
        if(checkdate($parts[2], $parts[1], $parts[3]))
            return true;
    return false;
}

Funktionen starter med først at tjekke at der kun er angivet tal mellem de to bindestreger.
Derefter validateres datoen via PHP-funktionen checkdate($month, $day, $year)  for om hver sektion i strengen er indenfor de tilladte værdier (f.eks. at man ikke har angivet 13 som en måned og 32 som en dag).

Simpel funktion, der er god til at valider bruger-input inden de f.eks. viderebehandles eller lagres i en database.

God fornøjelse !

Dynamics NAV: Custom text boxes on a Request Form in a Dataport

This article is in English because Microsoft Dynamics NAV (better known as Navision) is a world-wide product. Please excuse my English – it is not the best!

In this article I will explain how you can put custom text boxes on the Request Form in a Dataport-object.
As far as I know this solution works for Microsoft Dynamics NAV 5.0 SP1 and all earlier versions. I have not tested this on Dynamics NAV 2009, but my best guess is that this work-around works for the Classic Client in Dynamics NAV 2009 too.

The problem with the Request Form and custom text boxes is that when you put your custom text boxes on the Request Form, the normal text box for choosing what file to import/export will disapear.

To solve this problem you have to do the following steps:

  1. Create a new global variable - I will call the variable “VarFilename” in my example.
     
  2. Insert a new text box (don’t forget a label for the text box) from the Toolbox.
     
  3. Set the ID of the new text box to ’1′.
     
  4. Put the following code in the “OnAssistEdit()”-function of the new text box:
    CurrDataport.FILENAME := VarFilename;

Now run the Dataport and see that is works.

To follow NAV-guidelines remember to give the label, linked to the text box, the correct caption as if it was a standard Dataport, and remember to place the text box at the top of the Request Form.

Good luck with the coding! ;-)