Hi... i would be like to say thank you and grateful for someone who consider to help me...
i want to change this code:
function isPhoneValid() {
// 5 digits number
return ereg('^[0-9]${5}', $this->phone);
}
with adding strlen.. so become >5 digit number...
Regards,
kbluhm
02-18-2010, 03:14 AM
return ctype_digit( $this->phone ) && strlen( $this->phone ) >= 5;
Yes, this work fine... thank you n GBU bro, but how to mark this thread solved?
DaiWelsh
02-18-2010, 01:24 PM
or just
return ereg('^[0-9]${5,}', $this->phone);
{5} means exactly five digits
{5,10} means between 5 and 10 characters
{5,} means 5 or more characters
Incidentally I would think it should be '^[0-9]{5,}$' as $ indicates the end of the data and so should be at the end of the pattern, may work the other way but seems less correct to me.
Caveat: I always use PCRE regex functions preg_ rather than ereg_ but assuming ereg_ supports {5} it should support {5,} as well.
HTH,
Dai
kbluhm
02-18-2010, 01:31 PM
If you want to use preg_match(), it would be:
return ( bool ) preg_match( '/^\d{5,}$/', $this->phone );
And to mark the topic as resolved, I believe you'd edit it, and next to the subject line there should be a select-menu marked `Prefix`.
oh... that's several ways to solved this..