I need to check a string that comes from an ajax post with php, in particulare the source is a text area with this format:
[minute]:[price]
[minute]:[price]
[minute]:[price]
Example:
10:20
12:22.23
20:30.1
And so on, the minutes is an integer and the price could be a float with 0 to 2 decimals(10, 10.0, 10.00 are fine), I'm only able to check them in a simple way: double explode( "\n" and ":") and is_number + float on sub-element, but it looks pretty inconvenient, could someone suggests me an expression to use with preg_match?
looks pretty inconvenient, Why not try something fist and ask us why it is not working?(\d)+:(\d)+(.(\d)+)*- Check out this website for testing your regex: debuggex.com/#cheatsheet - I have only just started learning regex so there might be a better one but it worked for your 3 examples.