Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How can I block words and letter tags from being used

Am using the following code to block words and user tags from being made but I am wondering is there a better way of doing this?

[code]
procedure TNewForm.OKButClick(Sender: TObject);
var
s: string;
begin
if (Pos('@', NameEdit.Text) = 1) or
(Pos('(SUPPORT)', UpperCase(NameEdit.Text)) > 0) or
(Pos('(', UpperCase(NameEdit.Text)) > 0) or
(Pos('[', UpperCase(NameEdit.Text)) > 0) or
(Pos('{', UpperCase(NameEdit.Text)) > 0) or
(Pos(')', UpperCase(NameEdit.Text)) > 0) or
(Pos(']', UpperCase(NameEdit.Text)) > 0) or
(Pos('}', UpperCase(NameEdit.Text)) > 0) or
(Pos('-', UpperCase(NameEdit.Text)) > 0) or
(Pos('=', UpperCase(NameEdit.Text)) > 0) or
(Pos('[SUPPORT]', UpperCase(NameEdit.Text)) > 0) or
(Pos('{SUPPORT}', UpperCase(NameEdit.Text)) > 0) or
(Pos('(COORDINATOR)', UpperCase(NameEdit.Text)) > 0) or
(Pos('[COORDINATOR]', UpperCase(NameEdit.Text)) > 0) or
(Pos('{COORDINATOR}', UpperCase(NameEdit.Text)) > 0) or
(Pos('(VIP)', UpperCase(NameEdit.Text)) > 0) or
(Pos('[VIP]', UpperCase(NameEdit.Text)) > 0) or
(Pos('{VIP}', UpperCase(NameEdit.Text)) > 0) or
(Pos('SAGE-', UpperCase(NameEdit.Text)) > 0) or (Pos('HELP', UpperCase(NameEdit.Text)) > 0) or
(Pos('SUPPORT', UpperCase(NameEdit.Text)) > 0) or
(Pos('COORDINATOR', UpperCase(NameEdit.Text)) > 0) or
(Pos('ADMIN', UpperCase(NameEdit.Text)) > 0) or (Pos('SAGE', UpperCase(NameEdit.Text)) > 0) or
(Pos('SAGE=', UpperCase(NameEdit.Text)) > 0) then

begin
Application.MessageBox(PChar(
'Error: Member name is invalid because of reserved, or disallowed words.' +
#13 + 'Please try again!'), 'Unable to create!', mb_Ok or mb_IconWarning);
Exit;
end
else
begin
if length(NameEdit.Text) >= 3 then
begin
if length(PassEdit.Text) >= 5 then
begin
if DM.CountryTable.Locate('Name', CountryBox.Text, []) then
s := DM.CountryTable.FieldByName('N').AsString;
if DM.MainClient.Active then
DM.MainClient.Socket.SendText(CodeStr('NewUser' + NameEdit.Text + '' //0
+ PassEdit.Text + '' //1
+ s + '' //2
+ SexBox.Text + '' //3
+ AgeBox.Text + '' //4
+ DM.UserMAC + '' //5
+ EmailEdit.Text + ''//6
));
end
else
begin
MessageDLG(DM.labels[16], mtError, [mbOK], 0);
PassEdit.SetFocus;
end;
end
else
begin
MessageDLG(DM.labels[15], mtError, [mbOK], 0);
NameEdit.SetFocus;
end;
end;
end;
[/code]

Thanks alot

Slewis

Comments

  • sziszi81sziszi81 Posts: 80Member
    [b][red]This message was edited by sziszi81 at 2006-2-1 9:31:11[/red][/b][hr]
    [b][red]This message was edited by sziszi81 at 2006-2-1 9:29:49[/red][/b][hr]
    hey how about storing all those things in a constant array and check it with a cycle? it's easier to maintain and much shorter in code.
    u could use patterns, wildcards, whatever u want.


    And look at them...

    the [ character also excludes the [SUPPORT] and [COORDINATOR],...
    and ( character also excludes the (SUPPORT) and (COORDINATOR),...
    so you don't have to list all forms there.

    ADMIN, SAGE, VIP, HELP, SUPPORT, COORDINATOR, and the signs are enough.

    something like this should work:

    [code]
    const restrictedwords: array[1..n] of string =...

    function IsGoodName(name: string): boolean;
    var i: integer;
    goodname: boolean;
    begin
    goodname:=true;
    i:=1;
    while goodname and (i<=n) do
    begin
    goodname:=(Pos(restrictedwords[i],name)=0);
    i:=i+1;
    end;
    Result:=goodname;
    end;
    [/code]

    You don't even need the [b]goodname[/b] variable, you can you Result instead.


Sign In or Register to comment.