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? Link to comment https://forums.phpfreaks.com/topic/78269-preg-match/ 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. Link to comment https://forums.phpfreaks.com/topic/78269-preg-match/#findComment-396084 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 ? Link to comment https://forums.phpfreaks.com/topic/78269-preg-match/#findComment-396104 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. Link to comment https://forums.phpfreaks.com/topic/78269-preg-match/#findComment-396654 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.