Hola de nuevo.
Para no dejar las cosas por la mitad, una implementación para usar con un
TEdit:
Código:
// Grupo de caracteres no validos para nombre
const
char* wrongKey = "|°¬!\"#$%&/()='?\\¿¡@´¨+*~{[^}]`<>,;.:-";
// Limpiar Edit ingreso de nombre
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Edit1->Clear();
}
// Verificar en escritura
void __fastcall TForm1::Edit1KeyPress(TObject *Sender, char &Key)
{
TEdit *ed = static_cast<TEdit*>(Sender);
if((ed->SelStart+ed->SelLength == 0 && Key>=0x30 && Key<=0x39) ||
StrPos(wrongKey, String(Key).c_str()) != NULL)
Key=0;
}
// Verificar por copiado/pegado
void __fastcall TForm1::Edit1Exit(TObject *Sender)
{
TEdit *ed = static_cast<TEdit*>(Sender);
for(int i = 1; i <= ed->Text.Length();i++)
if (StrPos(wrongKey, ed->Text.c_str()+i) != NULL) {
MessageBeep(MB_ICONERROR);
ed->SetFocus();
}
}
Saludos
