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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.