Re: RegEx for "money" form field

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Someone (Someone_at_discussions.microsoft.com)
Date: 09/16/04


Date: Thu, 16 Sep 2004 06:30:27 -0700


"Evertjan." wrote:

> =?Utf-8?B?U29tZW9uZQ==?= wrote on 15 sep 2004 in
> microsoft.public.scripting.jscript:
>
> > Hey am trying to write a regex to test whether my form field has a
> > monetary value.
> >
> > The criteria is that the amount canot be more then 9 digits in length
> > and not more then 4 decimals. Decimal is optional So...
> >
> > 999999999.9999
> > 25.99
> > 100
> > 0.999
> >
> > Are all valid examples. So far I have this...
> >
> > ^\\d{1,9}(\\.\\d{1,4})$
>
> r = /^\d{1,9}(\.\d{1,4})?$/.test(value)
>
> ? = {0,1}

What does that mean?

I solved my problem with this expression: ^\\d{1,9}$|^\\d{1,9}\\.\\d{1,4}$
Am checking for one input or the other... Might not be the greatest way of
writting it but it works! ;)

Thanks

>
>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress,
> but let us keep the discussions in the newsgroup)
>
>



Relevant Pages