[thelist] reg expression question

Liorean Liorean at user.bip.net
Mon Oct 14 18:03:01 CDT 2002


At 12:59 2002-10-14 -0400, Michael Robertson wrote:
>I've been trying to come up with an expression that seems easy but it's
>not working. I want to match an integer that is at least 3 digits long and
>MIGHT have a comma:
>
>325
>3459
>3,459
>10300
>10,300
>
>are all acceptable examples.
>
>everytime i try to do something to match the comma it doesn't work. Any
>suggestions? Thanks

Can't be done with a single RegExp, I think. Check /^[0-9,]{3,}$/. If
match, then do a replacement of /,/ to '', then do a /\d{3,}/ check again.
If you're sure the user will only add the comma as a
group-of-three-starting-from-the-left delimiter, you could do
/^[0-9,]*,?\d{3}$/ to check it, though, or use /^(\d{1,3},?)*\d{3}$/ which
should work for that general case.



Oh, and a few other things:
- In most of Europe, and in large parts of the rest of the world, space is
used instead of comma as a number grouping character.
- Some countries use ', ´ or ` or characters like them, though.
- In most of Europe, and in large parts of the rest of the world, comma is
the decimal sign instead of point.

So, consider these things as well. At least allowing space instead of comma
would be good to do.

// Liorean




More information about the thelist mailing list