Unit mainunit;
Interface
Uses Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls;
Type tform1 = class (tform) label1: TLabel; edit1: tedit; button1: tbutton; procedure button1click (sender: Tobject); private {private declarations} public {public declarations}
Var Form1: TFORM1;
IMPLEMENTATION
{$ R * .dfm} function isvaildemailaddr (emailddr: string): boolean; var number, i: integer; // Number is used to give character '@' count Tempstr: string; begin tempstr: = emailaddr; Number: = 0; For i: = 1 to length (tempstr) Do Begin if (Tempstr [I] = '@') THEN INC; END; IF ((Number = 0) OR (Number> 1)) Then Result: = false // If the character '@', or the number is greater than 1, the else beg is illegal else begin if ((Tempstr [length = '@') or '@')) THEN Result: = false // If the character '@' position is at the beginning or end of the string, it is not legal ELSE BEGIN i: = POS ('@', tempstr); // Get the character '@' in the character string Delete (Tempstr, 1, I); // Get the remaining sub-gate IF behind the character '@' in the string: = false // If the remaining substrings are less than 3, Illegal else begin IF ((POS ('.', Tempstr) = 0) OR (POS ('.', Tempstr) = length (tempstr)) OR (POS ('.', Tempstr) = 1)) THEN RESULT : = False // If the remaining substrings do not contain characters '.', Or its position is at the beginning or end of the // substring, it is not legal else result: = true; // The above judgment is passed, then it is expressed The address string is legal END; END; end;
Procedure tForm1.Button1Click (Sender: TOBJECT); Begin if (edit1.text <> ') Then Begin if isvaildemailaddr (edit1.text) Then ShowMessage (' You entered email address format legal! ') Else ShowMessage (' you The input email address format is not legal! '); END; end;