Woodburn2006 Posted November 21, 2007 Share Posted November 21, 2007 after hours of trying i can not still get to grips with this function, i am trying to work it so that a user cannot enter anything different than this format: 00.000 it is for lap times so they could enter: 32.999 or something similar but it has to have 2 numbers before the decimal place and 3 after. can anyone help? Quote Link to comment Share on other sites More sharing options...
Orio Posted November 21, 2007 Share Posted November 21, 2007 <?php if(preg_match("/^\d{2}\.\d{3}$/", $str) == 1) //matches ... else //doesn't ... ?> Orio. Quote Link to comment Share on other sites More sharing options...
Woodburn2006 Posted November 21, 2007 Author Share Posted November 21, 2007 cool thanks, works well. is there any way of doing it so that the user can enter UP TO 3 numbers after the decimal place so that 32.33 is acceptable too ? Quote Link to comment Share on other sites More sharing options...
Orio Posted November 22, 2007 Share Posted November 22, 2007 Change the expression to: "/^\d{2,3}\.\d{3}$/" Orio. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.