I've got a project to do where it requires that some user input fields should have an input mask defined and that the data is validated against these input fields.

I was thinking of following a subset of the Visual Basic definition of input masks which follows:
MASK Purpose ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~ 0 Digit (0 to 9, entry required, plus [+] and minus [–] signs not a +llowed). 9 Digit or space (entry not required, plus and minus signs not allo +wed). # Digit or space (entry not required; plus and minus signs allowed) L Letter (A to Z, entry required). ? Letter (A to Z, entry optional)* A Letter or digit (entry required). a Letter or digit (entry optional)* & Any character or a space (entry required). C Any character or a space (entry optional)* . , : ; - / Literal character < Causes all characters to be converted to lowercase. > Causes all characters to be converted to uppercase. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * may remove this rule
The reason behind this is that most people I work with are techie enough to come up with input masks but not full regex. For example, its easier to do:
(C##) ### ####### or (+00) 000 0000000
Than to do
/^\(\+\d{2}\) \d{3} \d{7}$/
NB: I just wrote the regex out for an example, I have no idea if it works.

I have scouted around CPAN and found nothing that provides this kind of functionality. However, before I begin work on this I wondered if it had been done before (so I could download and install it) or if anyone had any comments on how to do this? If this doesn't exist anywhere I would consider posting it to CPAN only if nothing was there first.

I thought of simply removing the optional parts to the ruleset and then using something like pack, a dynamic regex or simply iterating through the chars in the string.

The resting place for these masks would be in a database next to the question they ask so would always be dynamic and variable in nature. Additionally, I may have to port this code to JavaScript (*shudder*) for various reasons.

Thanks

SP

In reply to Inputmask based variable validation by simon.proctor

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.