Page 1 of 1

Trouble getting number validation working

Posted: Mon Mar 08, 2004 2:55 am
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.

Posted: Mon Mar 08, 2004 3:01 am
by markl999
Much easier to use the ctype functions.
For example,

Code: Select all

if(ctype_digit($element)){
    return TRUE;
} else {
   return FALSE;
}

Posted: Mon Mar 08, 2004 5:40 am
by Shujaa
Aha thanks, that's awesome. Didn't know such a thing existed :O