Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: Input validation routines

From: SunandaDH:aol at: 27-Aug-2003 2:53

> Hi, has someone written a set of input validation routines/dialect, > where I can check data against some format specification? Those things > one knows from Excel, databases etc. for dates, number, strings, length > of input and so on. Thanks. Robe
Not as ambitious as that, but I did write this basic validation function that will check a field against a list of types: is-this?: func [ "Checks and cleans a string" Types [block!] "List of acceptable Rebol data types" Raw-data [string!] "Item to be checked" /local Block-data Clean-Data ][ ;; Returns: either Raw-data converted to its Rebol datatype ;; or False - if it is not one of the types on the list Block-data: copy [] error? try [block-data: to-block Raw-Data] either (length? Block-data) = 1 [ Clean-data: first Block-data][ Clean-data: Raw-data] foreach RebolType Types [ if (type? Clean-data) = get to-word RebolType [Return Clean-data] ] Return False ] Example of use: is-this? [tag! tuple!] "" == false is-this? [tag! tuple!] "" == is-this? [tag! tuple!] "xxx" == false is-this? [integer! money!] "" == false is-this? [integer! money!] "$100" == $100.00 is-this? [date! email! file!] "12-jan-04" == 12-Jan-2004 is-this? [date! email! file!] "[me--here--com]" == [me--here--com] is-this? [date! email! file!] "ddd" == false Sunanda.