- Original Poster
- #1
Help!
I've got 99% of my form validation sorted but one bit is bugging me.
All I want to do is check for symbols in the telephone number,
I pick up the variable from the form and check it like this:
function VerifyForm(&$values, &$errors)
{
if(!preg_match("[^0-9]",$values['telephone']))
$errors['telephone'] = 'no symbols';
if(empty($values['telephone']))
$errors['telephone'] = 'Please enter a telephone number';
}
The form field is this:
<p class="error"><?= $errors['telephone'] ?></p>
<p><input type="text" size="20" name="telephone" value="<?=htmlentities($values['telephone']) ?>"/></p>
If I put letters or symbols it returns the error. But it also tells me that 0-9 are symbols as well! It's going to be something really simple but I can't see it.
Note if you leave the field blank the correct error message displays.
The test form is here: http://www.aerin.co.uk/contactform/errors3.php
All the other fields work fine.
PS: This one works but just strips out the dodgy characters, I want to be a bit more user friendly: http://www.aerin.co.uk/contactform/errors.php
I've got 99% of my form validation sorted but one bit is bugging me.
All I want to do is check for symbols in the telephone number,
I pick up the variable from the form and check it like this:
function VerifyForm(&$values, &$errors)
{
if(!preg_match("[^0-9]",$values['telephone']))
$errors['telephone'] = 'no symbols';
if(empty($values['telephone']))
$errors['telephone'] = 'Please enter a telephone number';
}
The form field is this:
<p class="error"><?= $errors['telephone'] ?></p>
<p><input type="text" size="20" name="telephone" value="<?=htmlentities($values['telephone']) ?>"/></p>
If I put letters or symbols it returns the error. But it also tells me that 0-9 are symbols as well! It's going to be something really simple but I can't see it.
Note if you leave the field blank the correct error message displays.
The test form is here: http://www.aerin.co.uk/contactform/errors3.php
All the other fields work fine.
PS: This one works but just strips out the dodgy characters, I want to be a bit more user friendly: http://www.aerin.co.uk/contactform/errors.php
Last edited:
