Popup YouTube Video
Sheerpower Logo

Input Validation Rules: DATE, TIME, PATTERN & Filters


Concise guide to Sheerpower's VALID() rules for dates, times, expressions, menus, routines, and powerful FILTER pipelines with RESTORE for multi-step validation.

What You'll Learn

Sheerpower's VALID(text$, vrules$) evaluates input against readable, composable rules like date dmony, required, pattern, and more. You can also pre-process text with filter steps (trim, case-change, replace/remove, etc.) and use restore to validate both the cleaned and the original input in one pass.

Quick Reference

  • INTEGER / NUMBER / DIGITS / LETTERS / UCASE / LCASE — what the text is made of
  • ALLOW lo TO hi / ALLOW a, b, c — the values allowed: numbers after integer or number, dates after date, otherwise text
  • DISALLOW — the same forms, refused
  • LENGTH n / MINLENGTH n / MAXLENGTH n — exactly, at least, at most n characters
  • DECIMALS n — at most n decimal places (after number)
  • DATE DMONY — DD-Mon-YY (e.g., 01-Jan-99)
  • DATE DMONCY — DD-Mon-CCYY (e.g., 01-Jan-2000)
  • FULLTIME — CCYYMMDD HHMMSS or YYMMDD HHMMSS
  • PATTERN — Matches a rule string (see Pattern)
  • REQUIRED — Non-empty, not just spaces
  • YES/NO — Only YES, NO, Y, or N (case-insensitive)
  • VRULES — Validates the rule set itself
  • PRINTMASK — Checks a print-format mask
  • EXPRESSION — Legal Sheerpower expression
  • CODE — Legal Sheerpower code block
  • MENU — Legal INPUT MENU description
  • ROUTINE — Routine name exists
  • FILTER — ltrim, rtrim, trim, ucase, lcase, replace, remove, change; plus restore
Return Values
Most rules return TRUE (1) or FALSE (0). The fulltime rule's documentation below states FALSE (0) as the failure value; confirm in your build. Consistently check your return values when mixing rules.

INTEGER, NUMBER, DIGITS, LETTERS — What the Text Is

integer accepts a whole number, number any number, digits only the characters 0–9, letters only letters; ucase and lcase accept one case only. Rules chain with a semicolon and every one must pass.

// Expect: 1, 0, 1, 0 print valid('42', 'integer') print valid('4.2', 'integer') print valid('4.2', 'number') print valid('abc', 'digits') end

ALLOW, DISALLOW, LENGTH, DECIMALS — The Values Allowed

These are the rules that save a loop around an input: the range a number may fall in, the values a text may take, how long it may be. allow lo to hi is a range and allow a, b, c a list; the two combine (allow 1 to 5, 10). What the values ARE follows the rule before them: after integer or number they are numbers, after a date rule they are dates (and today is a value), with no such rule they are text compared case-blind. disallow takes the same forms and refuses them. length n is an exact length, minlength n and maxlength n the bounds, decimals n the most decimal places a number may have.

// Expect: 1, 0, 0, 1, 0, 1, 0, 1, 0 print valid('50', 'integer; allow 1 to 120') print valid('121', 'integer; allow 1 to 120') print valid('abc', 'integer; allow 1 to 120') print valid('green', 'allow red, green') print valid('13', 'integer; disallow 13') print valid('abcdef', 'length 6') print valid('abcde', 'length 6') print valid('abc', 'minlength 2; maxlength 4') print valid('1.255', 'number; decimals 2') end

On an input field the same words go in the valid option, and the prompt repeats until the answer passes — no loop to write: input 'Age', valid 'integer; allow 1 to 120': age, or in a screen form <valid "required; integer; allow 1 to 120": Age ###>.

DATE DMONY — DD-Mon-YY

Checks if text$ is a legal date in DD-Mon-YY format and returns TRUE (1) or FALSE (0).

// Expect: 1 text$ = '01-Jan-99' vrule$ = 'date dmony' print valid(text$, vrule$) end

DATE DMONCY — DD-Mon-CCYY

Checks if text$ is a legal date in DD-Mon-CCYY format and returns TRUE (1) or FALSE (0).

// Expect: 1 text$ = '01-Jan-2000' vrule$ = 'date dmoncy' print valid(text$, vrule$) end

FULLTIME — Date + Time

Checks if text$ is a legal date/time in either CCYYMMDD HHMMSS or YYMMDD HHMMSS format. Returns TRUE (1) or FALSE (0).

// Expect: 1 then 1 text$ = '20000122 010101' text2$ = '990122 010101' vrule$ = 'fulltime' print valid(text$, vrule$) print valid(text2$, vrule$) end

PATTERN — Custom Rule Match

Matches text$ against a rule string. See Section 6.5.4 PATTERN(str_expr1, str_expr2) for details.

REQUIRED — Non-blank

Returns TRUE if text$ is not null and not only spaces.

// Expect: 1 then 0 text$ = 'a b c d' text2$ = ' ' vrule$ = 'required' print valid(text$, vrule$) print valid(text2$, vrule$) end

YES/NO — Strict Yes/No

Returns TRUE if text$ is one of: YES, NO, Y, N.

// Expect: 1, 1, 0 text$ = 'yes' text2$ = 'n' text3$ = 'a' vrule$ = 'yes/no' print valid(text$, vrule$) print valid(text2$, vrule$) print valid(text3$, vrule$) end

VRULES — Validate Rule Set

Checks if a vrules$ string itself is a legal set of validation rules.

// Expect: 1 print valid('integer', 'vrules') end

PRINTMASK — Format Mask

Validates that text$ is a legal print mask.

// Expect: 1 text_str$ = '##.##' vrule$ = 'printmask' print valid(text_str$, vrule$) end

EXPRESSION — Sheerpower Expression

Returns TRUE if text$ is a legal Sheerpower expression.

// Expect: 1 then 0 text_str$ = 'total = a% + 30' text_str2$ = '##~-###' vrule$ = 'expression' print valid(text_str$, vrule$) print valid(text_str2$, vrule$) end

CODE — Sheerpower Code

Returns TRUE if text$ is syntactically legal Sheerpower code.

// Expect: false path taken a$ = "print 'hello, ' name$" if not valid(a$, 'code') then print 'false' end if end

MENU — INPUT MENU Description

Validates a menu description string for use with INPUT MENU.

// Expect: 1 text_str$ = '%multi,a,b,c' vrule$ = 'menu' print valid(text_str$, vrule$) end

ROUTINE — Existence Check

TRUE if the named routine exists; FALSE otherwise.

// Expect: 1 then 0 text$ = 'do_totals' text2$ = 'test_nos' vrule$ = 'routine' print valid(text$, vrule$) print valid(text2$, vrule$) end routine do_totals: private mytotal, desc$ mytotal = 15 desc$ = 'Test Totals' print desc$; mytotal end routine

FILTER — Clean, Transform, Validate

Filters modify text$ before validation. Chain multiple steps with semicolons. Supported filters:

  • ltrim$ — remove leading spaces, control characters, and DEL
  • rtrim$ — remove trailing spaces, control characters, and DEL
  • trim$ — remove leading and trailing spaces, control characters, and DEL
  • ucase$ — uppercase
  • lcase$ — lowercase
  • replace — replace chars: old=new, old2=new2, ...
  • remove — remove listed chars from text$
  • change — complex remap (see CHANGE$)
  • restore — restore original (pre-filter) text for later validations in the same rule chain

Examples

FILTER + REMOVE / REPLACE / TRIM

// Expect: true, true, true text$ = 'abcd10' vrules$ = 'filter remove "10"; letters' text2$ = 'ab1cd1' vrules2$ = "filter replace '1'='e'; letters" text3$ = ' 1234 ' vrules3$ = "filter trim; number" if valid(text$, vrules$) then print 'true' if valid(text2$, vrules2$) then print 'true' if valid(text3$, vrules3$) then print 'true' end

FILTER + RESTORE

Use restore when you need a filtered check and then a second check on the original text later in the chain.

// Expect: true text$ = "123" vrule$ = "filter replace '1'='a'; restore; number" if valid(text$, vrule$) then print 'true' end
Design Tip
Problem: Real-world text is messy—extra spaces, odd casing, stray characters.
Solution: Standardize with filter (trim/case/remap), then restore to re-validate the untouched original when needed.
Efficiency: A single valid() call can handle a pipeline of filters and checks—fewer passes, clearer intent.
Takeaway: Treat validation as a readable pipeline: filter ...; restore; rule; rule; ...

Putting It Together

Combine rules with semicolons to form pipelines. Validate and transform in one statement, and lean on vrules to sanity-check complex rule strings at load time.

(Show/Hide Sheerpower Validation Rules Takeaways)
Hide Description

    

       


      

Enter or modify the code below, and then click on RUN

Looking for the full power of Sheerpower?
Check out the Sheerpower website. Free to download. Free to use.