[REBOL] Re: Input validation routines
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/