New Function: Validate ()

HMG Samples and Enhancements

Moderator: Rathinagiri

Post Reply
User avatar
Claudio Ricardo
Posts: 367
Joined: Tue Oct 27, 2020 3:38 am
DBs Used: DBF, MySQL, MariaDB
Location: Bs. As. - Argentina

New Function: Validate ()

Post by Claudio Ricardo »

Hi... I have created a new function that I needed and could not find a similar one.

Code: Select all

// Función Validate () Comprueba si los caracteres de cCadena están validados por cChars (retorna .T.)
// Uso Validate (cName,"abcd345") Si cName = a-d y 3-5 retorna .T. sinó retorna .F.
// Creada por Claudio Ricardo Folgán 03/2021

Function Validate (cCadena,cChars)

LOCAL cValid := .T.
LOCAL i

	For i = 1 To Len (cCadena)
	
		If ! Lower ( SubStr (cCadena,i,1)) $cChars
		
			cValid := .F.
			
		EndIf
		
	Next

Return cValid
Usage:

Code: Select all

LOCAL cNombre := Fupper ( AllTrim ( GetProperty ("Config" , "Text_Nombre" , "Value")))
LOCAL cPass1 := GetProperty ("Config" , "Text_Pass1" , "Value")
LOCAL cPass2 := GetProperty ("Config" , "Text_Pass2" , "Value")
LOCAL cCadena := "abcdefghijklmnñopqrstuvwxyz0123456789"		// List of valid characters

    If Empty (cNombre)

        MsgStop ("Debe escribir un nombre de usuario." , "Error.")
		Return Nil

    EndIf

	If ! Validate (cNombre,cCadena)				// Compruebo que sólo ingresen caracteres válidos
	
        MsgStop ("Sólo son válidos caracteres a-z y 0-9 sin acentos ni espacios." , "Error.")
		Return Nil

    EndIf

    If Empty (cPass1)

        MsgStop ("Debe escribir una contraseña de usuario." , "Error.")
		Return Nil

    EndIf

	If ! Validate (cPass1,cCadena)				// Compruebo que sólo ingresen caracteres válidos
	
        MsgStop ("Sólo son válidos caracteres a-z y 0-9 sin acentos ni espacios." , "Error.")
		Return Nil

    EndIf

// here the rest of code
In Cli**er i had VALID:

Code: Select all

ASN = SPACE(1)
@ 18,25 SAY "Desea continuar ? S/N  " COLOR"BR+"  GET ASN PICT "@!" VALID ASN $ "SN"
READ
I hope it usefull.
Corrige al sabio y lo harás más sabio, Corrige al necio y lo harás tu enemigo.
WhatsApp / Telegram: +54 911-63016162
User avatar
vientopamperosur
Posts: 59
Joined: Thu Aug 28, 2014 10:13 am
DBs Used: DBF, SQLite, MySQL, MariaDB, PostgreSQL
Location: Buenos Aires
Contact:

Re: New Function: Validate ()

Post by vientopamperosur »

Muy buena, gracias por compartir.
User avatar
bpd2000
Posts: 1207
Joined: Sat Sep 10, 2011 4:07 am
Location: India

Re: New Function: Validate ()

Post by bpd2000 »

Also refer this discussion
viewtopic.php?f=9&t=3254
BPD
Convert Dream into Reality through HMG
User avatar
Claudio Ricardo
Posts: 367
Joined: Tue Oct 27, 2020 3:38 am
DBs Used: DBF, MySQL, MariaDB
Location: Bs. As. - Argentina

Re: New Function: Validate ()

Post by Claudio Ricardo »

bpd2000 wrote: Fri Mar 26, 2021 11:57 am Also refer this discussion
viewtopic.php?f=9&t=3254
Thanks.
Corrige al sabio y lo harás más sabio, Corrige al necio y lo harás tu enemigo.
WhatsApp / Telegram: +54 911-63016162
User avatar
luisvasquezcl
Posts: 1258
Joined: Thu Jul 31, 2008 3:23 am
Location: Chile
Contact:

Re: New Function: Validate ()

Post by luisvasquezcl »

Gracias Claudio
Post Reply