How to allow variable number of character
I want to have a pattern for email address [email protected]
but I want any number of letter fro each part. How can I do that?
Its hard to have a "mask" when the blank bits can be a variable number of chars, I don't beleive this is possible at this point (and maybe never). A plain ol Regex and textbox may be the best option here.
RE: As you type input validation using RegExp
I have started working on this, issue #46 I had exactly this problem, I wanted to define the input mask with as RegExp. Regular regexp does not have an API that can be used to validate input as I type.
I have written a Regexp package( incr-regex-package ) that can do just that. Now I have to incorporate it into this package.
If anyone is interested in helping me, let me know.
The long answer
The basic issue is masked input designed with a rather inflexible mask definition language. Yes it can be extended but the basic limitation is the fixed size input mask design.
Of course there is a we have a mask definition language that everybody knows Regular Expressions. But here is the problem, a regular expression in JavaScript matches against the entire input, i.e. it needs the entire string. Only then will it tell you whether you have a match or not.
I was not able to find any library that given a regular expression would do a partial match and let you know is more input is require or you have come to the end of the match.
So a simple email regexp might be:
var rx = /[-a-zA-Z0-9_.]+@[-a-zA-Z0-9_.]+/;
rx.match('me@') // fails
What we need is an incremental regular expression matcher that will tell you:
- DONE - matched and no more input is allowed
- MAYBE - the string matches but it will accept more characters
- FAIL - the string will not match
But we also need more than that, we would like to guide the user to, i.e. show a mask. Anyway, since I could not find such a package I write one incr-regex-package.
Next i am planning to clone this package and build an extension to this package that accepts regular expression as the mask language. Then you will be able to match against email or anything else you can define using a regular expression.
The code works very well and is quite fast considering it uses pure JavaScript. My regexp is not intended to compete with the built-in RegExp which is very very good, but it can be used for as you type input validation.
It is now possible to do this see Demo, the demo allows you to test with you own regular expressions.