954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Pascal: Validation

I hope that someone can help me with this problem.
I need to allow only characters in input:
Example I have procedure to add records to my database

procedure AddRec( var fff:Myfiletype; FileOpen: boolean);
var rec:myrec; tmp:MyFileType;
begin
    assign(tmp,'data.tmp');
    reset(fff); rewrite(tmp);
    seek(fff,0);
    while not eof(fff) do
    begin
    read(fff,rec); write(tmp,rec);
    end;
    {$I-}
    write('Write 1st. city : '); readln(rec.P1);
    {$I+}
    if (ioresult<>0) then begin myfileerr:=7; ferror; end
    else
    begin
    write(tmp,rec);
    rewrite(fff); reset(tmp); seek(tmp,0);
    while not eof(tmp) do
    begin
    read(tmp,rec); write(fff,rec);
    end;
    end;
    close(tmp); reset(fff); seek(fff,0);
end;

So... I need to allow only characters from a to z to input.
I would be grafetful if someone could help me with this problem

Pekulacis
Newbie Poster
1 post since Jan 2011
Reputation Points: 10
Solved Threads: 0
 

compare each character to the ASCII a..z or A..Z range of characters. if character outside those ranges, message user that the character is bad, then allow user to re-enter.

ennis
Newbie Poster
5 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

Can you do something like this?

Procedure TfrmRasCorrections.dfFirstNameKeyPress(Sender: TObject;
Var Key: Char);
Begin
//The #8 allows backspace to be used.
//The #32 is for space bar to be used.
//'A'..'Z' allows uppercase. 'a'..'z' allows lowercase letters.
If not (key in ['A'..'Z', 'a'..'z', #8, #32]) then
Begin
Key:= #0;
Beep; //I'm using a beep but this is where you could use your error message.
End;
End;

Maggy0426
Newbie Poster
3 posts since Jan 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: