Forum Moderators: coopster
I hope you can help.
Im sure this is quite easy to do but being very new to php im a little stuck. I'm wanting to ensure the length of a string entered by the user is >0 and <12 (ie a telephone number.) Im also wanting to ensure that the users cant enter any non numerical data and that one of the phone fields CAN be blank (ie they only have to provide one telephone number. This is what ive got so far -
if (empty($_POST['homephonefirst']) && empty($_POST['mobilenumberfirst'])){
$error_msg['homephonefirst'] = '<div class=message>Please enter at least one contact telephone number</div>';
} elseif (ereg('^[^0-9 ]+$' , $_POST['homephonefirst'])){
$error_msg['homephonefirst'] = '<div class=message>Invalid character in Home telephone number</div>';
} elseif (ereg('^[^0-9 ]+$' , $_POST['mobilenumberfirst'])){
$error_msg['homephonefirst'] = '<div class=message>Invalid character in Mobile telephone number</div>';
}
Can someone point me in the right direction?
Many many thanks in advance
$home = $_POST['homephonefirst'];
$mobile = $_POST['mobilenumberfirst'];
if (empty($home) && empty($mobile)){
$error_msg['homephonefirst'] = '<div class=message>Please enter at least one contact telephone number</div>';
} else if (!empty($home) &&!ctype_digit($home)){
$error_msg['homephonefirst'] = '<div class=message>Invalid character in Home telephone number</div>';
} else if (!empty($mobile) &&!ctype_digit($mobile)){
$error_msg['homephonefirst'] = '<div class=message>Invalid character in Home telephone number</div>';
}
[php.net...]
you could also look at this
[webmasterworld.com...]