Indeed, the condition ival = email
is true
iff ival
and email
are identical strings. Since ival
is @
, the condition is true iff email
is exactly @
.
You want to check if @
is found inside email
. To do this, you can use the Pos
function, which returns the 1-based index of the first character of the first occurrence of a substring within a string, or 0
is the substring isn't found in the string:
if Pos('@', email) = 0 then
ShowMessage('The email address must contain @.');
Notice that there really isn't any need for a variable to hold the at character.
In modern versions of Delphi, it is better to write
if not email.Contains('@') then
ShowMessage('The email address must contain @.');
using TStringHelper.Contains
, since this is easier to read.