Trouble getting number validation working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Shujaa
Forum Newbie
Posts: 13
Joined: Tue Jan 27, 2004 12:14 pm

Trouble getting number validation working

Post by Shujaa »

Code: Select all

function isDigits($element)
{
	if (eregi("^ї0-9]+$", $element)) //function to check if a string is digits only
	{	return TRUE;} 
	else 
	{	return FALSE;}
}
That's my function to check whether any given string consists of only numbers or not. If it contains only 0-9 it SHOULD return True, and False otherwise. But for some reason I cannot for the life of me get it to work properly! I've tried testing the regular expression on a reg-exp website and it works fine there. Can anyone see anything wrong with my code? Thanks.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Much easier to use the ctype functions.
For example,

Code: Select all

if(ctype_digit($element)){
    return TRUE;
} else {
   return FALSE;
}
Shujaa
Forum Newbie
Posts: 13
Joined: Tue Jan 27, 2004 12:14 pm

Post by Shujaa »

Aha thanks, that's awesome. Didn't know such a thing existed :O
Post Reply