Grupo
¿cómo puedo validar que en un TEXTBOX no pongan carácteres especiales?, es decir si tengo esto:
NOMBRE COMPLETO: _Jorge %Posadas Ch*
Necesito encontrar los carateres especiales en ese TEXTBOX a indicarle al usuario que "NO SE PERMITEN CARACTERES ESPECIALES", claro está que los acentos NO deben considerarse como carácteres especiales.
De antemano agradezcp su ayuda
Carcateres especiales
Moderator: Rathinagiri
-
- Posts: 174
- Joined: Mon May 19, 2014 7:43 pm
- DBs Used: DBF, SQLite, MS-SQL, ACCESS, MariaDB (en proceso)
- Location: Morelia, Mich. México
- Contact:
Carcateres especiales
Cordialmente
POSADAS SOFTWARE
Jorge Posadas Ch.
Programador independiente
Morelia, Mich.
M é x i c o .
Movil +52 44 3734 1858
SKYPE: jorge.posadasch
Email: posoft@gmx.com
POSADAS SOFTWARE
Jorge Posadas Ch.
Programador independiente
Morelia, Mich.
M é x i c o .
Movil +52 44 3734 1858
SKYPE: jorge.posadasch
Email: posoft@gmx.com
Re: Carcateres especiales
Hi, Jorge.
I would create a string of the characters that you WILL allow, then use a do while loop (based on the length of the text) to step through the string of characters in the textbox, exiting only when you reach the end of the text (and go to the next process) or you find a character in the text that isn't allowed (and you go to an error message).
Maybe there's a faster or easier way, but I've used that in the past, so I know it works.
Hope this helps! Good luck!
I would create a string of the characters that you WILL allow, then use a do while loop (based on the length of the text) to step through the string of characters in the textbox, exiting only when you reach the end of the text (and go to the next process) or you find a character in the text that isn't allowed (and you go to an error message).
Maybe there's a faster or easier way, but I've used that in the past, so I know it works.
Hope this helps! Good luck!
- vagblad
- Posts: 160
- Joined: Tue Jun 18, 2013 12:18 pm
- DBs Used: MySQL,DBF
- Location: Thessaloniki, Greece
Re: Carcateres especiales
Hi Jorge,
I use the OnChange event usually to check things like that.See a small example.
Hope i understood what you need correctly and it helps.
Best Regards
Vagelis
I use the OnChange event usually to check things like that.See a small example.
Code: Select all
#include <hmg.ch>
FUNCTION Main
Public cSpecialChars := '!@#$%^&*()'
DEFINE WINDOW Main AT 291 , 543 WIDTH 550 HEIGHT 350 TITLE "Textbox Input Check" MAIN
DEFINE TEXTBOX Text_1
ROW 20
COL 30
WIDTH 200
HEIGHT 24
FONTNAME "Arial"
FONTSIZE 9
TOOLTIP ""
ONCHANGE TestInput()
TABSTOP .T.
VALUE ""
END TEXTBOX
END WINDOW
CENTER WINDOW Main
ACTIVATE WINDOW Main
PROCEDURE TestInput()
Local cString := Main.Text_1.Value
Local cChar := Substr(cString,len(cString),1)
If cChar $ cSpecialChars
msgdebug('The character ' + cChar + ' is not allowed!')
Main.Text_1.Value := Substr(cString,1,len(cString)-1)
Main.Text_1.CaretPos := len(cString) + 1
EndIf
Best Regards
Vagelis
- Attachments
-
- Main.zip
- (1.48 MiB) Downloaded 159 times
Vagelis Prodromidis
Email: vagblad@gmail.com, Skype: vagblad
Email: vagblad@gmail.com, Skype: vagblad
- mustafa
- Posts: 1158
- Joined: Fri Mar 20, 2009 11:38 am
- DBs Used: DBF
- Location: Alicante - Spain
- Contact:
Re: Carcateres especiales
Hola jorge.posadas
Aquí tienes el mismo resultado a la inversa en un
supuesto que se pregunta "Married ? : Yes or No"
solo permite el TEXTBOX --> Yes or No
Saludos
Mustafa
Aquí tienes el mismo resultado a la inversa en un
supuesto que se pregunta "Married ? : Yes or No"
solo permite el TEXTBOX --> Yes or No
Code: Select all
#include <hmg.ch>
FUNCTION Main
SET CODEPAGE TO UNICODE
DEFINE WINDOW Main AT 291 , 543 WIDTH 550 HEIGHT 350 TITLE "Textbox Input ONLOSTFOCUS" MAIN NOSIZE NOMAXIMIZE
DEFINE LABEL Label_1
ROW 030
COL 050
WIDTH 270
HEIGHT 020
VALUE "Married ? : Yes or No"
FONTNAME "Arial"
FONTSIZE 9
TOOLTIP ""
FONTBOLD .T.
FONTITALIC .F.
FONTUNDERLINE .F.
FONTSTRIKEOUT .F.
HELPID Nil
VISIBLE .T.
TRANSPARENT .F.
ACTION Nil
AUTOSIZE .F.
BACKCOLOR NIL
FONTCOLOR NIL
END LABEL
DEFINE TEXTBOX Text_1
ROW 060
COL 050
WIDTH 200
HEIGHT 24
FONTNAME "Arial"
FONTSIZE 9
TOOLTIP "Married , Yes or No"
ONCHANGE Nil
ONGOTFOCUS Main.Label_1.FontBold := .T.
ONLOSTFOCUS( If (.NOT.(This.Value $ UPPER("YESNO") ) , EVAL({|| This.SetFocus, This.Value:= 'NO'}), NIL ) , Main.Label_1.FontBold := .F. )
FONTBOLD .F.
FONTITALIC .F.
FONTUNDERLINE .F.
FONTSTRIKEOUT .F.
ONENTER Nil // Lo mismo vale para ONENTER ---> Value $ "YESNO" // Ditto for ONENTER ---> Value $ "YESNO"
HELPID Nil
TABSTOP .T.
VISIBLE .T.
READONLY .F.
RIGHTALIGN .F.
DISABLEDBACKCOLOR Nil
DISABLEDFONTCOLOR Nil
MAXLENGTH Nil
BACKCOLOR { 253,209,209 }
FONTCOLOR NIL
INPUTMASK "!!!"
FORMAT Nil
NUMERIC .F.
VALUE "NO"
END TEXTBOX
DEFINE TEXTBOX Text_2
ROW 090
COL 050
WIDTH 200
HEIGHT 24
FONTNAME "Arial"
FONTSIZE 9
TOOLTIP ""
ONCHANGE Nil
ONGOTFOCUS Main.Label_1.FontBold := .T.
ONLOSTFOCUS NIL
FONTBOLD .F.
FONTITALIC .F.
FONTUNDERLINE .F.
FONTSTRIKEOUT .F.
ONENTER Nil
HELPID Nil
TABSTOP .T.
VISIBLE .T.
BACKCOLOR { 253,209,209 }
FONTCOLOR NIL
NUMERIC .F.
VALUE " "
END TEXTBOX
END WINDOW
Main.Text_1.SetFocus
CENTER WINDOW Main
ACTIVATE WINDOW Main
Return Nil
Mustafa