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

Input validation routines

 [1/18] from: robert::muench::robertmuench::de at: 27-Aug-2003 8:29


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. Robert

 [2/18] from: SunandaDH:aol at: 27-Aug-2003 2:53


Robert:
> 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!] "12.5.5.6" == 12.5.5.6 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.

 [3/18] from: nitsch-lists:netcologne at: 27-Aug-2003 8:53


Am Mittwoch, 27. August 2003 08:29 schrieb Robert M. Muench:
> 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. Robert
Not the validation itself, but a text-feel with hook for keystroke, and it can flash. currently used for conference/messenger. i can imagine something like number: charset [opt "-" #"0" - #"9"] layout[field validate [some number]] whould that help? -Volker

 [4/18] from: AJMartin:orcon at: 27-Aug-2003 18:55


Robert wrote:
> 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. I have. For a number of Rebol datatypes. Look for the names with "^" appended. [ Rebol [ Name: 'Patterns Title: "Patterns" File: %"Patterns.r" Author: "A J Martin" Owner: "Aztecnology" Rights: "Copyright 2003 A J Martin, Aztecnology." eMail: [Rebol--orcon--net--nz] Web: http://www.rebol.it/Valley/ Needs: [%Map.r] Tabs: 4 Language: 'English Date: 14/August/2003 Version: 1.1.0 ] Fail^: [to end skip] ; A rule that always fails. Succeed^: [] ; A rule that always succeeds. Octet: charset [#"^(00)" - #"^(FF)"] Digit: charset "0123456789" Digits: [some Digit] Upper: charset [#"A" - #"Z"] Lower: charset [#"a" - #"z"] Alpha: union Upper Lower Alphas: [some Alpha] AlphaDigit: union Alpha Digit AlphaDigits: [some AlphaDigit] Control: charset [#"^(00)" - #"^(1F)" #"^(7F)"] Hex: union Digit charset [#"A" - #"F" #"a" - #"f"] HT: #"^-" SP: #" " LWS: charset reduce [SP HT #"^(A0)"] LWS*: [some LWS] LWS?: [any LWS] LF: #"^(0A)" WS: charset reduce [SP HT newline CR LF] WS*: [some WS] WS?: [any WS] Sign^: [#"+" | #"-"] Integer^: [opt Sign^ Digits] Decimal^: [opt Sign^ Digits #"." Digits] Tuple^: [1 3 Digit some [#"." 1 3 Digit]] Graphic: charset [ #"^(21)" - #"^(7E)" #"^(80)" #"^(82)" - #"^(8C)" #"^(8E)" #"^(91)" - #"^(9C)" #"^(9E)" - #"^(9F)" #"^(A1)" - #"^(FF)" ] Printable: union Graphic charset reduce [SP #"^(A0)"] Integer^: Digits Decimal^: [Digits #"." Digits] Pair^: [Digits #"x" Digits] Money^: [0 3 Alpha #"$" Digits #"." 2 Digit] Tag^: [#"<" thru #">"] ; A Windows file name cannot contain any of these characters: Forbidden: charset {\/:*?"<>|} Line_End: [newline | end] Blank_Line: [LWS? newline] Blank_Lines: [any Blank_Line] make object! [ Zone: [Sign^ 1 2 Digit #":" 2 Digit] set 'Time^ [1 2 Digit #":" 1 2 Digit opt [#":" 1 2 Digit]] Long-Months: remove map Rebol/locale/Months func [Month [string!]] [ reduce ['| copy Month] ] Short-Months: remove map Rebol/locale/Months func [Month [string!]] [ reduce ['| copy/part Month 3] ] Month: [1 2 Digit | Long-Months | Short-Months] Separator: charset "/-" Day: [1 2 Digit] set 'Date^ [ [ [Day Separator Month Separator [4 Digit | 2 Digit]] | [4 Digit Separator Month Separator Day] ] opt [#"/" [Time^ opt Zone]] ] ] make object! [ Permitted: exclude Printable Forbidden Filename: [some Permitted] Folder: [Filename #"/"] Relative_Path: [some Folder] Absolute_Path: [#"/" any Relative_Path] set 'File^ [ [Absolute_Path opt Filename] | [Relative_Path opt Filename] | Filename ] ] make object! [ Permitted: exclude Printable Forbidden Drive^: [Alpha #":"] Filename^: [some Permitted] Folder^: [Filename^ #"\"] Relative_Path^: [some Folder^] Absolute_Path^: [#"\" any Relative_Path^] set 'Local_File^ [Drive^ Absolute_Path^ opt Filename^] ] make object! [ Char: union AlphaDigit charset "-_~+*'" Escape: [#"%" Hex Hex] Chars: [some [Char | Escape]] User: [some [Char | Escape | #"."]] Domain-Label: Chars Domain: [Domain-Label any [#"." Domain-Label]] IP-Address: [Digits #"." Digits #"." Digits #"." Digits] Host: [Domain | IP-Address] set 'eMail^ [User #"@" Host] Pass: Chars Port: [1 4 Digit] User-Pass-Host-Port: [ [User #":" Pass #"@" Host #":" Port] | [User #":" Pass #"@" Host] | [User #":" Host] | [Host #":" Port] | [Host] ] Fragment: [#"#" Chars] Query: [ #"?" [ any [opt #"&" Chars #"=" [Chars | Absolute-Folder] | Chars | Absolute-Folder opt [#":" Port]] ] ] Fragment_Or_Query: [Fragment | Query] Extension: [#"." 1 4 Char] File: Chars Folder: [some ["../" | "./" | [File opt [#"." Chars] #"/"]]] set 'URI_Relative-Folder Relative-Folder: [ Folder opt File opt Extension opt Fragment_Or_Query | opt Folder File opt Extension opt Fragment_Or_Query | opt Folder opt File Extension opt Fragment_Or_Query | opt Folder opt File opt Extension Fragment_Or_Query ] set 'URI_Absolute-Folder Absolute-Folder: [#"/" opt Relative-Folder] Net-Folder: ["//" User-Pass-Host-Port opt [Absolute-Folder]] Scheme: [Alpha some Char] set 'URL^ [Scheme #":" Net-Folder] Local-File: [#"%" [Absolute-Folder | Relative-Folder]] set 'URI^ [eMail^ | URL^ | Local-File] ] ] Andrew J Martin ICQ: 26227169 http://www.rebol.it/Valley/ http://valley.orcon.net.nz/ http://Valley.150m.com/

 [5/18] from: petr:krenzelok:trz:cz at: 27-Aug-2003 9:14


Robert M. Muench wrote:
>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. Robert >
ha, Robert progressing in db area, right? :-) I proposed field/match item, kind of a dialect. It is quite some time I last time looked at VID style sources, but I think that event handlers live in separate context or so. My idea was to be able to e.g. have fields like: (99) - (999 999) where "9" means 'number from 0 - 9, whereas e.g. "x" means char. Cursor should move so that you would be able to type only numbers, chars "() -" (those would be skipped, you would not be able to delete them, etc. 99.99.999 - date format - I saw various implementations :-) Well, in DOS, all letters were of the same width, but in GUI environments, it is not the same, so " . ." move as you type, it is a question how to do properly hilighting (some implementations failed, as you was able to delete those date-format dots, etc.) I think that dialects/rules are the way to go. -pekr-

 [6/18] from: g:santilli:tiscalinet:it at: 27-Aug-2003 10:22


Hi Andrew, just a small note, On Wednesday, August 27, 2003, 8:55:55 AM, you wrote: AJM> Fail^: [to end skip] ; A rule that always fails. You don't need the TO, [end skip] will always fail anyway. Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/

 [7/18] from: AJMartin:orcon at: 27-Aug-2003 20:57


Gabriele wrote:
> AJM> Fail^: [to end skip] ; A rule that always fails. > > You don't need the TO, [end skip] will always fail anyway.
Thanks, Gabriele! Andrew J Martin Improving steadily... ICQ: 26227169 http://www.rebol.it/Valley/ http://valley.orcon.net.nz/ http://Valley.150m.com/

 [8/18] from: robert:muench:robertmuench at: 27-Aug-2003 14:18


> -----Original Message----- > From: [rebol-bounce--rebol--com] [mailto:[rebol-bounce--rebol--com]]
<<quoted lines omitted: 8>>
> layout[field validate [some number]] > whould that help?
Hi, yes that would help a lot :-)) And if we can add a handler that is called if the pattern is violated (to display a help message) that would be perfect. Is this 'feel plug-in able into an existin application? Robert

 [9/18] from: robert:muench:robertmuench at: 27-Aug-2003 14:18


> -----Original Message----- > From: [rebol-bounce--rebol--com] [mailto:[rebol-bounce--rebol--com]]
<<quoted lines omitted: 4>>
> I have. For a number of Rebol datatypes. Look for the names > with "^" appended.
Hi Andrew, thanks a lot. I have to look into this. Robert

 [10/18] from: robert:muench:robertmuench at: 27-Aug-2003 14:18


> -----Original Message----- > From: [rebol-bounce--rebol--com] [mailto:[rebol-bounce--rebol--com]]
<<quoted lines omitted: 3>>
> Subject: [REBOL] Re: Input validation routines > ha, Robert progressing in db area, right? :-)
Petr, you see I don't forget your input, it just sometimes takes some time :-)) Yes, you are right. I'm progrssing into DB and data-form area.
> My idea was to be able to e.g. have fields like: > > (99) - (999 999) > > where "9" means 'number from 0 - 9, whereas e.g. "x" means > char. Cursor should move so that you would be able to type only
numbers,
> chars "() -" (those would be skipped, you would not be able to delete
them, etc. Yes, something like this. My idea it to have VID styles that have a field 'validation where you attach such a format string too and that will either be valiated while typing or when leaving the field. Further an error-handler exists, which can pop-up a help string. layout [ ... field validate [(99) - (999 999)] validate-error [alter "Plase only enter numbers"]
> "99.99.999" - date format - I saw various implementations :-)
BTW: Do you have a reference how those format strings are expressed? I mean we have dialects and I'm sure we can clone this common way. I would follow the common way, as a lot of people know it.
> Well, in DOS, all letters were of the same width, but in GUI > environments, it is not the same, so " . ." move as you type, it is
a question
> how to do properly hilighting (some implementations failed, as you was
able to
> delete those date-format dots, etc.)
IMO in this case a check-as-you-type handler is needed. This handler will analyze the string (on a positional base) and insert the dots at the right place ;-)) and update the GUI. Robert

 [11/18] from: robert:muench:robertmuench at: 27-Aug-2003 14:18


> -----Original Message----- > From: [rebol-bounce--rebol--com] [mailto:[rebol-bounce--rebol--com]]
<<quoted lines omitted: 4>>
> Not as ambitious as that, but I did write this basic > validation function that will check a field against a list of types:
Thanks for the input. This might help to convert input data into a Rebol conform way for storing. How about the other way? For example: In a field only month and year should be entered. I'm going to convert it into a 'date!, where a day is added. Now I want to output this data in the form month/year. I can imagine a rountine like yours, where I specify a handler for each datatype that than gets called. Robert

 [12/18] from: maximo:meteorstudios at: 27-Aug-2003 10:39


what I did in a prior version of liquid was an automatic datatype conversion system where you specify an output datatype and supply an input data. basically the function switches on entry datatype and then swithes again on the output datatype, depending on if it is at all possible to convert to-from. if any of the switches failed, I would return an empty data of the type requested in out format. It works really well, some of it is in the steel down load, within the steel-utils package. the method filter, as-decimal, as-integer, all try to convert to-from differrent datatypes. not many datatypes are covered, but those that are, really are usefull... for example, you can extract integer/decimal data out of any string even if it is full of formating text like labels. -max ----------- meteor Studios, T.D. ----------- Never Argue with an idiot. They will bring you down to their level and beat you with experience

 [13/18] from: greggirwin:mindspring at: 27-Aug-2003 9:02


Hi Robert, RMM> BTW: Do you have a reference how those format strings are expressed? I RMM> mean we have dialects and I'm sure we can clone this common way. I would RMM> follow the common way, as a lot of people know it. I think the COBOL PIC format was the initial inspiration that a lot of others emulated and built upon. Clipper might have been the king, but a true DB person could probably say for sure. RMM> IMO in this case a check-as-you-type handler is needed. This handler RMM> will analyze the string (on a positional base) and insert the dots at RMM> the right place ;-)) and update the GUI. Robert That kind of thing can be *very* hard to get right Robert, in my experience. It's not just the technical side of things, but the user interaction experience you design. Having things modified as you type can confuse some people, and can end up being a lot of work if you get into things like masks where you want to skip over some chars automatically when they cursor or backspace, not to mention shift+cursor to highlight text then typing or hitting delete or backspace. Even if you get it to work how *you* want, some users will just never be comfortable with it. I'm all for *anything* that helps users, but validation after the fact and better help information to show them what's valid can be used with the same prototype-form approach, just without the key-level interaction bit. I guess I'm saying I'd get the validation part working before worrying about key-handling integration. Just FWIW. -- Gregg

 [14/18] from: maximo:meteorstudios at: 27-Aug-2003 11:24


> -----Original Message----- > From: Gregg Irwin [mailto:[greggirwin--mindspring--com]]
<<quoted lines omitted: 6>>
> interaction bit. I guess I'm saying I'd get the validation part > working before worrying about key-handling integration.
liquid (and thus liquid-vid) lets you insert a validation hook for each field. by creating preset styles, you allow the input in the fields to be bound to a certain type. The advantage, is that not only the ui field gets validated, but any other method which can set the value (like a load or value update). For liquid-vid, anything that is invalid, resets the field to its previous value when enter is pressed. Try it in the colorbox demo... if you write something that is not valid in the individual color text fields, (like a non-numeric value), then the previous color will be replaced after enter (instead of putting it to 0). The validation IS hand written, but if other as-datatype filters where created, then its really easy to setup. my two cents. ciao! -MAx PS: the STEEL site is still NOT updated <sigh!>. The season is fall (automn, for some of you) and a lot of things are going around my house, so I have like 1-2 hours per day to work on it... :-( IT IS PROCEEDING... JUST VERY SLOWLY .... I have worked hard on looking at licensing (it takes so much time to do)... and have done a lot of work on remark.r also, my internet connection at home is being capricious (modem is not very stable...) so I lost one complete evening tryin to get a new USB modem to work, without success... :-( I was severely irritated...TONIGHT I AM UPDATING THE SITE (major overhaul in content and structure, mainly because of all that new remark.r stuff) and START PUTTING THE FIRST DOCS ON LINE. Next time I'm keeping my mouth shut (like I'd done so far) as long as its not online... sorry for all the b***shit! ------------- Steel project coordinator http://www.rebol.it/~steel

 [15/18] from: nitsch-lists:netcologne at: 27-Aug-2003 17:41


Am Mittwoch, 27. August 2003 14:18 schrieb Robert M. Muench:
> > -----Original Message----- > > From: [rebol-bounce--rebol--com] [mailto:[rebol-bounce--rebol--com]]
<<quoted lines omitted: 5>>
> > Not the validation itself, but a text-feel with hook for keystroke, > > and it can flash. currently used for conference/messenger.
should be used for conference/messenger for a spellckecker.
> > > > i can imagine something like
<<quoted lines omitted: 4>>
> called if the pattern is violated (to display a help message) that would > be perfect. Is this 'feel plug-in able into an existin application?
currently callbacks to global words, so only one field. could be made local to field of course. have a look at developer/users/volker/spellck2/spellck2.r i found only this callbacks: spellcheck-trigger?: func [char] [] triggers are space and such, check only finished words. is called on every keystroke. returns true on space currently to check word. spellcheck-last-word: func [string][] is called with the position before the trigger-char so the last word can be extracted. if one files, the field flashes red. look for their call and place your own check there for experiments. rejecting input completely is lacking, but should be easy. do the same check before face/action is called. -Volker

 [16/18] from: didier:cadieu:freesbee at: 27-Aug-2003 23:01


Re: Input validation routines
> 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. Robert
Hi all I have made a custom field style to convert on the fly user input to another datatype. This face also filter the key allowed to be entered in the field. So the user can't input any forbidden char. For exemple, to input an integer value by allowing only digit and minus, the layout spec will be : view layout [ style field-style filter-field convert-to integer! filter "-0123456789" ] 'convert-to and 'filter are specifics to this style and optional of course. 'convert-to can be follow by the desire datatype or by a function that take the face for parameters and must return the result of the conversion. the result is stored in the property "value" of the object and is set to none! if the conversion failed. By default, "value" is a copy of "text" 'filter can be follow by a string!, a block of char/string (like 'charset function one) or a bitset!. In all case this value represent the char that can be typed by the user. If the key pressed is not in this spec, the input value is discard and doesn't appear in the field. You can find this style and a test script here : http://www.agora-dev.org/forums/view.php?bn=rebol_view&key=1055268965 or on my rebsite : http://membres.lycos.fr/didec/rebsite/ (REM: click "filter-field-style" to put it in the cache before trying the demo) Doc and more examples are in the header of filter-field-style.r Hope it can help you Didec

 [17/18] from: zokie:libero:it at: 27-Aug-2003 18:19


Hello Robert On 27-Ago-03, Robert M. Muench wrote:
> 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. Robert
I don't know if my solution is what your are looking for. I make a private validation function, which checks input when user press OK button to confirm input. If v-func finds one or more errors then clears field(s) and gui does not return anything. You can see the code into my project: Site Address Book, but you must know that is experimental version now and only EDIT and ADD button are working. Please refer to: http://utenti.lycos.it/zlab/pub/rebol/index.html Regards -- "Where did you get all those facts!?!"

 [18/18] from: robert:muench:robertmuench at: 29-Aug-2003 7:41


> -----Original Message----- > From: [rebol-bounce--rebol--com] [mailto:[rebol-bounce--rebol--com]]
<<quoted lines omitted: 4>>
> I don't know if my solution is what your are looking for. > ...
Hi, thanks, I will have a look at the weekend. Robert

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted