View Full Version : A little help with a simple RegEx please

23 Jun 2009, 11:41 PM
Hi. This is probably not the place to ask it, but I've run across a block in the road whilst developing in ExtJs. I need a maskRe that does the following

1. The first character has to be either 'R', 'M' or 'L' (not case sensitive).
2. The next 0 to 8 characters have to be numeric

So that's it basically. Doesn't sound too hard but for the life of me I can't get it to work. This is what I have so far ..

maskRe: /^[R|M|L][0-9]{0,8}/i

if anyone could point me in the right direction that would be very much appreciated.

24 Jun 2009, 12:13 AM


Which, as Expresso says, matches:

- Beginning of line or string
- Any character in this class: [RML]
- Any digit, between 0 and 8 repetitions

24 Jun 2009, 12:45 AM
Thanks, however it doesn't work for me :-? :-/

With this RegEx I'm able to type more than one R (or L, or M) and no digits whatsoever. What am I doing wrong :(

maskRe: /^[RML]\d{0,8}/i,

24 Jun 2009, 12:59 AM
add a trailing $

maskRe: /^[RML]\d{0,8}$/i,

24 Jun 2009, 1:25 AM
Thanks. The result however is quite the same :( I can type multiple R, M or Ls and still no digits. Argh :-/

24 Jun 2009, 1:28 AM
maskRe is only used to filter keypresses.

You want:

maskRe: /[RML0-9]/, // filter keypresses
regex: /^[RML]\d{0,8}$/i, // validation

(Ext will still allow you to enter invalid text, but validation will fail)

24 Jun 2009, 1:32 AM
Ahh! Now I understand. Thank you, this helped me a lot. And thanks the rest of you guys. ~o)