Input Mask

teoyh

Member
I have a form which need to capture the following input in a single field. I have brief the user that they need to follow the convention when they key in the lotus notes name but they simple cannot remember

How can i create a input mask to ensure that the user will follow the standard convention as follow;
Name/Position-Dept/Organisation

eg David/Snr Engineer-Design/EA Services

Thank you in advance.
 
It's not possible with the input mask plugin we use at the moment, which is getting a but long in the tooth. I've been looking at this one:

https://github.com/RobinHerbots/Inputmask

... which is all singing, all dancing, with lots of bells and whistles, and would do what you need (a variable length mask). It's a bit heavyweight, but we can live with that for the extra functionality. The main problem is that it would break backward compat with existing mask definitions. There's nothing the old one can do that this one can't, it just does things differently.

So for now, you best bet is to enforce it with a JS event which check it and barfs if it doesn't match a regular expression. So a 'blur' event on that field, which does something like ..

Code:
if (!this.getValue().test(/^[^/]+\/[^/]+-[^/]+\/[^/]+$/)) {
   alert("How many times do I have to tell you to use Name/Position-Dept/Organisation format?");
}

In that regex ...

/.../ the whole pattern is surrounded by slashes, not part of the pattern, just tells Javascript this is a regex
^ means "start of string"
[^/]+ means "one or more of anything except a /
\/ means "a /"
- means -
$ means "end of string"

So it's ...

start
one or more of anything except a /
followed by a /
followed by one or more of anything except a /
followed by a -
followed by one or more of anything except a /
followed by a /
followed by one or more of anything except a /
end

You could get more specific, and force alphanumeric plus acceptable other chars, but that pattern will get you the basic shape.

-- hugh
 
Thanks for writing this reply really appreciate your time and effort to explain this to me thank you i will try it out
 
We are in need of some funding.
More details.

Thank you.

Staff online

Members online

Back
Top