كود :
uses dateutils;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Mask,dateutils;
type
TForm1 = class(TForm)
MaskEdit1: TMaskEdit;
procedure MaskEdit1Change(Sender: TObject);
procedure MaskEdit1KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
Function DateIsValide(s:string):boolean;
var
a,m,j: string;
aa,mm,jj:word;
aaa,mmm,jjj:integer;
valid:boolean;
begin
a:=Copy(s,7,4); if pos(' ',a)=0 then aaa:=strtoint(a) else aaa:=0;
m:=Copy(s,4,2); if pos(' ',m)=0 then mmm:=strtoint(m) else mmm:=0;
j:=Copy(s,1,2); if pos(' ',j)=0 then jjj:=strtoint(j) else jjj:=0;
aa:=Integer(aaa);
mm:=Integer(mmm);
jj:=Integer(jjj);
if IsValidDate(aa,mm,jj) then valid:=true else valid:=false;
result :=valid;
end;
procedure TForm1.MaskEdit1Change(Sender: TObject);
begin
if (MaskEdit1.Text<>' / / ') and (MaskEdit1.SelStart=10) then if DateIsValide(MaskEdit1.Text) then
ShowMessage(MaskEdit1.Text+ '--->'+'Date Correcte') else ShowMessage(MaskEdit1.Text+ '---> '+'Date Incorrecte') ;
end;
procedure TForm1.MaskEdit1KeyPress(Sender: TObject; var Key: Char);
begin
if not (Key in [#8,#13,'0'..'9']) then Key:=#0;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
MaskEdit1.EditMask:='!##/##/####;1;_';
end;
end.