Regex accept numeric only. First character can’t be 0

If you’re looking at something like a price, you need to consider that 0.99 is probably perfectly valid. For something like that, I would simply start with a non-complex ^[0-9]*(\.[0-9]{0,2})?$ (again there may be edge cases that may make it more complex like three digits after the decimal point and so on) and allow leading zeroes, since they don’t “damage” the value in anyway.

It it must start with a non zero, just change the initial [0-9]* to a [1-9][0-9]*. For integers only (as seems to be indicated by your added sample data), that would be:

^[1-9][0-9]*$

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)