Click to See Complete Forum and Search --> : checking string


amrigo
01-26-2005, 01:47 PM
Hi
I have a sistem that sned sms messages typing the numbers in a textarea.

they must have the local area code and the number and they must be separated by a comma :

eg.:

4898570946,4899640940,4896947644,4499680446,4896988749,4499644473,4899648858,4898038798,4898888680,4 896833535,4898043904,4899030459,4896940878,4898458963,4899045488,4899684968,4898488084,4898048938,48 98363084

How can i check if they are all right ? and not like : 48,98709876,
the rule is after the number must be a comma and after the final number and before the first numbermust be no coma .

thank´s in advance!

NogDog
01-26-2005, 03:11 PM
if(preg_match("/^[0-9]{10}(,[0-9]{10})*$/", $string))
{
# it's valid
}
else
{
# it's invalid
}

amrigo
01-27-2005, 04:52 AM
thank´s a lot!

what exactly this espression means?
/^[0-9]{10}(,[0-9]{10})*$/

ShrineDesigns
01-27-2005, 05:19 AM
/^[0-9]{10}(,[0-9]{10})*$/
^ means at the begining of subject or line
[0-9]{10} means a number that is 20 chars long and are in the range from 0 to 9
* means 0 or more times
$ means at the end of subject or line

amrigo
01-27-2005, 07:04 AM
thank´s a lot