Jump to content

[SOLVED] ereg HELP ...


shakeit

Recommended Posts

Hello everybody... You've helped me out a couple of times and I am still comming back :-)

 

I need some help on a ereg issue, where I want to make a function where ONLY digits are possible when writing something in a field... i.e. only 0,1,2,3,4,5,6,7,8,9,10,.....

 

However, I thought the function below did that, but only to a certain point... if I write only letters then I will get false, which is ok.. but if I write digits first and then letters, 55aabb, then I get true...

 

Do you see my problem? I only want it to allow digits, nothing else:

 

 

public function validatePhone($validate)

{

$goodChars = "^[0-9]";

 

if( ereg("$goodChars",$validate) )

{

 

// if there are less than 8 digits, then its not correct.

if( strlen($validate) < 8 )

{

return false;

}

else

{

return true;

}

 

}

else

{

return false;

}

 

}

 

PS! I also have the same problem when I only want to allow letters in another function .. So please help me, AGAIN :-) Thanx in advance

Link to comment
https://forums.phpfreaks.com/topic/88411-solved-ereg-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.