Hi regex-gurus!
I´m getting crazy with a 'little' Problem in regex. All i want is a number which allows this Format "nn,nn"
So i made this regular expression: ([0-9][0-9])?,[0-9][0-9]
It works fine, but when the user just enters "12" then it should result in "12,00" so that he don´t always have to enter "00".
You understand what i mean?
How can i explain in regular expressions that the number should be filled up with "00" behind the "," if the user just entered 2 numbers?
Thanks for your help!
Greetings from Austria
Tom
'default value' or 'fill-up' in RegEx?
Moderator: General Moderators
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: 'default value' or 'fill-up' in RegEx?
After validating the input, you can use the following regex to format your values:
Although there probably is a built-in method in PHP for formatting (numerical) values, but the only thing I know is a bit of regex...
Code: Select all
$value = preg_replace('/^(\d\d)$/', "$1,00", $value);Re: 'default value' or 'fill-up' in RegEx?
sprintf() should be able to handle this.