Search

Hi all,
I am trying to adjust the 'number' regular expression of the text input field to accept dots and comma's (because dutch prices can contain comma's and dot's)
Regular expressions are pretty much abracadabra to me but i managed to change the acception of dot's by comma's;

by changing

/^-?(?:d+(?:.d+)?|.d+)$/i

to /^-?(?:d+(?:,d+)?|,d+)$/i

But how can i change it to accept both comma's and dots?

I've tried this: /^-?(?:d+(?:.,d+)?|.,d+)$/i
and /^-?(?:d+(?:.,d+)?|.,d+)$/i

But no luck... I'am pretty sure someone can help me out here
Thanks

Edit: The code seems to get a bit scrambled in the code tags, but i hope you get my point...

Try

/^-?(?:\d+(?:(\.|,)\d+)?|(\.|,)\d+)$/i

I've escaped the code properly in this example, so it's a direct copy and paste. It's untested though...

Thanks,
That works for dots or comma's, but not with both.
I am gonna stick with the dot's for now, cause it seems the comma's don't go well with the format-number() function...

I've escaped the code properly in this example

How did you do that?

Try this one, I've added + for the dot/comma so there can be one or more of either.

/^-?(?:\d+(?:(\.|,)+\d+)?|(\.|,)+\d+)$/i

When you add a backslash in to escape a character, you need to escape the backslash with another one for the forum.

Thanks again,
I've tested it and it works... but not quite :)
Your solution only works when de dot and comma appear right after another .,
But not for: 10.000,50 which is what i am looking for...

it seems the comma's don't go well with the format-number() function

This is a well-known issue. XSLT only accepts strings as numbers if the decimal separator is a dot (i.e. a decimal point). You may, however, use the translate()function, to change your (string) format accordingly.

Ah, I see then... Maybe a simpler regex is what you're after. The following fits your needs perfectly

((\d)+(\.|,)\d+)+$

Nope, sorry that one throw's an error after submission.
I've tried some variation's on it but i just can't seem to get the logic of it...

You may, however, use the translate()function, to change your (string) format accordingly.

Thanks, yep that's working, i can use this function to replace the dot's with comma's

That'll work for now. thank's guys

When I get some time, I shall try that again, it works locally in my regex tester, but that has been known to lie.

Great, no hurries! it's not a major issue

designermonkey was close :). Try:

/^-?(\d+|[\.,]\d+)+$/

It should handle things like:

  • .0
  • ,0
  • 0.0
  • 0,0
  • 0.0,0
  • 0,0,0
  • 0.0.0,0
  • etc...

And any of those above but with preceding "-". But that may be not enough, if You want to make sure that only one of dots or commas are used first, and other one used as last.

That one does the trick!
I've tried all sorts of combinations and they where all working. also 00.000,00

Cheers

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details