Re: RegEx: Dash Problem
Thanks for your suggestion! It turns out I was using the clean function of CakePHP's Sanitize class. It was doing something to my dashes :) One I moved that function AFTER my validation, everything worked great! KS On Mar 8, 5:00 am, Graham Weldon gra...@grahamweldon.com wrote: Hey, Try escaping the hyphen: \- That should work out for you. Cheers, Graham Weldon w.http://grahamweldon.com e. gra...@grahamweldon.com p. +61 407 017 293 On Sat, 7 Mar 2009 16:02:58 -0800 (PST), KS ksush2...@gmail.com wrote: Hi there, This might not be a cakePHP issue, but here goes... I use CakePHP + WAMP on Windows. My problem is that whenever there is a dash in a pattern and an input string has a dash, no match occurs. As a result, validation fails (like the built in e-mail and phone number validations). I have tried using a custom validation method with the following code: function valid_phone($data) { $pattern = ^[0-9]{3}-[0-9]{4}$; $phone_no = trim($data['phone']); if (ereg($pattern, $phone_no)) return 1; else return 0; } If I remove the dash from the pattern and input 7 digits, everything works fine. If I add the dash and input something like 123-45657, validation fails. This is not the only pattern I've tried, all with the same results. Any ideas? Thank you! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
RegEx: Dash Problem
Hi there, This might not be a cakePHP issue, but here goes... I use CakePHP + WAMP on Windows. My problem is that whenever there is a dash in a pattern and an input string has a dash, no match occurs. As a result, validation fails (like the built in e-mail and phone number validations). I have tried using a custom validation method with the following code: function valid_phone($data) { $pattern = ^[0-9]{3}-[0-9]{4}$; $phone_no = trim($data['phone']); if (ereg($pattern, $phone_no)) return 1; else return 0; } If I remove the dash from the pattern and input 7 digits, everything works fine. If I add the dash and input something like 123-45657, validation fails. This is not the only pattern I've tried, all with the same results. Any ideas? Thank you! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: RegEx: Dash Problem
Hey, Try escaping the hyphen: \- That should work out for you. Cheers, Graham Weldon w. http://grahamweldon.com e. gra...@grahamweldon.com p. +61 407 017 293 On Sat, 7 Mar 2009 16:02:58 -0800 (PST), KS ksush2...@gmail.com wrote: Hi there, This might not be a cakePHP issue, but here goes... I use CakePHP + WAMP on Windows. My problem is that whenever there is a dash in a pattern and an input string has a dash, no match occurs. As a result, validation fails (like the built in e-mail and phone number validations). I have tried using a custom validation method with the following code: function valid_phone($data) { $pattern = ^[0-9]{3}-[0-9]{4}$; $phone_no = trim($data['phone']); if (ereg($pattern, $phone_no)) return 1; else return 0; } If I remove the dash from the pattern and input 7 digits, everything works fine. If I add the dash and input something like 123-45657, validation fails. This is not the only pattern I've tried, all with the same results. Any ideas? Thank you! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---