JuJoGuAl
JuJoGuAl

Reputation: 119

Error with the limiter {} in regexp

Hey guys I have a problem! I want to make a reg exp for this: J-XXXXXXXX-X (where X are numbers), what I've done is:

if (rif.match("^ (j | J) (-) ([0-9] {8}) (-) ([0-9] {1}) $")) {
    alert("OK");
} else {
    alert("OK");
}

but does not work, because when you place a data field to "1", it does nothing.

looking at the code it shows me google chrome (see source code), I watch this:

if (rif.match("^ (j | J) (-) ([0-9]) (-) ([0-9]) $")) {
    alert("OK");
} else {
    alert("OK");
}

and I can not see the "{8}" that each Regular expression, what's happening?

Upvotes: 1

Views: 95

Answers (1)

Carter
Carter

Reputation: 2870

Remove the whitespace so it looks like...

if (rif.match("^(j|J)(-)([0-9]{8})(-)([0-9]{1})$")) {
    alert("OK");
} else {
    alert("NO");
}

See this fiddle: http://jsfiddle.net/CPWjv/

Upvotes: 3

Related Questions