delphi下实现很简单哈,响应Onchange事件就可以老
const
EDT_MAXLENGTH = 6;
procedure TForm1.AfterConstruction();
begin
inherited AfterConstruction();
fStaticStr := 'abc';
Edit1.MaxLength := EDT_MAXLENGTH;
Edit1.Text := fStaticStr;
end;
// -----------------------------------------------------------------------------
procedure TForm1.Edit1Change(Sender: TObject);
begin
if not AnsiStartsText(fStaticStr, Edit1.Text) then
begin
Edit1.Text := fStaticStr;
Edit1.SelStart := Length(fStaticStr);
Beep();
end;
end;