Page 1 of 1

check if a string starts with an integer

Posted: Wed Apr 30, 2003 7:21 am
by runelore
Hi I wanna check if a string starts with an integer, I know I need to use a pregnatch in some way but for the life of me I cant seem to get it right, anyone help? thanks....

Posted: Wed Apr 30, 2003 7:21 am
by runelore
sorry, check if a string starts with a number.. Sort of got the jargon mixed up there. : )

Posted: Wed Apr 30, 2003 7:40 am
by twigletmac
Try something like:

Code: Select all

$string = '12something';
if (preg_match('/^[0-9]/', $string)) {
    // string starts with number
} else {
    // string doesn't start with a number
}
Mac

Posted: Wed Apr 30, 2003 9:30 am
by runelore
Thank you very much, that is exactly what I needed to work with, thanks again..