RLJ Posted October 2, 2010 Share Posted October 2, 2010 Hi, I currently have some PHP scripts that verify form data using ereg() as follows: if (ereg(".",$var1)==0) { //do something } where instead of the argument "." I also use "\@" or "\....*", etc. to test whether certain form input is in the correct format (e.g. testing for a valid email address, etc.). However, I have understood that ereg() is being deprecated. What is the best/easiest function to replace ereg() with? Thanks! Link to comment https://forums.phpfreaks.com/topic/214995-verifying-form-data-replacement-for-ereg/ Share on other sites More sharing options...
.josh Posted October 2, 2010 Share Posted October 2, 2010 preg_match Would be the pcre equivalent. The patterns will pretty much be the same, only real difference is that the preg_xxx functions require an opening/closing delimiter in the pattern and modifiers (if needed) are specified after the closing delimiter. So for instance: ereg(".",$var1) would be preg_match("~.~",$var1) // ~ is used as the pattern delimiter. or for instance, eregi(".",$var1) // case in-sensitive would be preg_match("~.~i",$var1) // i modifier added to make it case in-sensitive Link to comment https://forums.phpfreaks.com/topic/214995-verifying-form-data-replacement-for-ereg/#findComment-1118387 Share on other sites More sharing options...
RLJ Posted October 3, 2010 Author Share Posted October 3, 2010 Cheers! Just one more question: how do I use preg_match to write a very simple line of code to check whether a price is in the correct format? All I want to do is allow only numbers "0-9" and a fullstop "." and make sure the entered price has between 1 and 5 digits. Also, there has to be at least one number before the "." and I want to convert e.g. 89 to 89.00 and 5.5 to 5.50 etc. o and also I want to replace "," with "." before checking so that someone can enter a price in european format: e.g. 5,50 Hopefully that is clear. I can do all of those things separately, but have been struggling to combine them. Thanks for your help. Link to comment https://forums.phpfreaks.com/topic/214995-verifying-form-data-replacement-for-ereg/#findComment-1118540 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.