Advertisement
eurismarpires

Expressoes regulares Delphi

Jul 3rd, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.51 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs,RegularExpressions, StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Button1: TButton;
  12.     Edit1: TEdit;
  13.     Button2: TButton;
  14.     procedure Button1Click(Sender: TObject);
  15.     procedure Button2Click(Sender: TObject);
  16.   private
  17.     { Private declarations }
  18.   public
  19.     { Public declarations }
  20.   end;
  21.  
  22. var
  23.   Form1: TForm1;
  24.  
  25. implementation
  26.  
  27. {$R *.dfm}
  28.  
  29. procedure TForm1.Button1Click(Sender: TObject);
  30. var strRegExp:string;
  31. begin
  32.   strRegExp := '[0-9]{11}';
  33.   if TRegEx.IsMatch(edit1.Text, strRegExp) = False then
  34.   begin
  35.     Application.MessageBox('CPF Inválido','Atenção!',MB_OK+MB_ICONWARNING);
  36.     Abort;
  37.   end
  38.   else
  39.   begin
  40.     Application.MessageBox('CPF Correto','Atenção!',MB_OK+MB_ICONWARNING);
  41.   end;
  42. end;
  43. procedure TForm1.Button2Click(Sender: TObject);
  44. var strRegExp:string;
  45. begin
  46.   //MOC MDF-e 3.00a - Leiaute      - expressao regular
  47.   //https://dfe-portal.sefazvirtual.rs.gov.br/Mdfe/Documentos#
  48.   strRegExp := '(((20(([02468][048])|([13579][26]))-02-29))|(20[0-9][0-9])-((((0[1-9])|(1[0-2]))-((0[1-9])|(1\d)|(2[0-8])))|((((0[13578])|(1[02]))-31)|(((0[1,3-9])|(1[0-2]))-(29|30)))))';
  49.   if TRegEx.IsMatch(edit1.Text, strRegExp) = False then
  50.   begin
  51.     Application.MessageBox('Data Inválida','Atenção!',MB_OK+MB_ICONWARNING);
  52.     Abort;
  53.   end
  54.   else
  55.   begin
  56.     Application.MessageBox('Data Correta','Atenção!',MB_OK+MB_ICONWARNING);
  57.   end;
  58.  
  59. end;
  60.  
  61. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement