sid0972 Posted February 10, 2013 Share Posted February 10, 2013 till now my guess was this /^\d+\.?\d{1,2,3}$/ It should accept a whole number, like 123456 or a decimal, like 123.456, but should allow MAX 3 decimal places. but this isn't seem to be working. what's wrong with it?? Link to comment https://forums.phpfreaks.com/topic/274307-regex-to-accept-a-whole-number-or-a-decimal-number/ Share on other sites More sharing options...
PaulRyan Posted February 10, 2013 Share Posted February 10, 2013 Try this: /^\d+\.?\d{1,3}$/ Link to comment https://forums.phpfreaks.com/topic/274307-regex-to-accept-a-whole-number-or-a-decimal-number/#findComment-1411595 Share on other sites More sharing options...
requinix Posted February 10, 2013 Share Posted February 10, 2013 1. The entire decimal part should be optional, not just the decimal point. Otherwise you're setting a minimum number of digits (two, with the \d+ and the \d{1,}). 2. {1,2,3} is entirely invalid syntax. It's a range, not a list of possible counts. I'd add parentheses to PaulRyan's solution. /^\d+(\.\d{1,3})?$/ Link to comment https://forums.phpfreaks.com/topic/274307-regex-to-accept-a-whole-number-or-a-decimal-number/#findComment-1411596 Share on other sites More sharing options...
sid0972 Posted February 11, 2013 Author Share Posted February 11, 2013 cool its working now thanks both of you Link to comment https://forums.phpfreaks.com/topic/274307-regex-to-accept-a-whole-number-or-a-decimal-number/#findComment-1411736 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.