TextBox lets the user enter strings. In practice, however, these strings often represent integers, currency amounts, percentages – and that’s just the numeric objects that the end-user may enter. One might also enter email addresses, hyperlinks, street addresses (or parts thereof), ISBN numbers, phone numbers, passwords, … the list goes on.
Ideally, the user should get immediate feedback when he violates the object’s syntax rules – and any other per-entry rules (minimum/maximum values, etc.). Immediate feedback means “perform the check in the browser, if at all possible.” (TextBox has all the event-handlers needed to trigger such checks.)
But of course, we must also execute the same check on the server side, since the browser-side can’t be trusted. And to ensure that it really is the same check, we should be executing the same Python code in both places.
At the moment, this is more difficult than it looks. Step one is usually to validate syntax. Accordingly, a first step is usually to import re
, Python’s regular expression module, and have it compile some standard syntax-checkers (to ensure consistency across many entry fields). Once a value’s syntax is “known good”, then we may convert the string to additional formats, if needed, for further testing (e.g., min/max).
Unfortunately, re.compile()
does not seem to be recognized browser-side. This probably eliminates any possible reliance on PyPi’s many validation modules. But from what I’ve seen so far, they’re not aimed at testing individual strings, anyway.
So, what validation tools (Python modules, functions, classes, etc.) currently are available, that work on Anvil’s browser-side and server-side?