I’m trying to pop in a function that will stop anybody putting in more than 8 characters into a form field but I’m not too sure of the exact script I need.
I have been playing with this:
if ($_POST['email'] < 8 ) {
echo 'Your password can only be 8 characters or less';
?>
<input name="email" type="text" id="email" />
But it just opens in the browser with the error 'Your password can only be 8 characters or less' even before I get to run the form field.
Can anyone give me a few pointers as I’m still new to all this PHP stuff?
Thanks a mil
Brian
8 characters - form field
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Code: Select all
if (!empty($_POST['email']) && (strlen($_POST['email']) > 8 )) {
echo 'Your password can only be 8 characters or less';Thanks folks this worked a treat. I have actually got a max length too in the form field but if I’m right this will just cut of any characters after a certain length. Now I have a facility where a user can change a password and if I don’t limit the password input to a certain amount then (via php validation) somebody unknowns to themselves could enter a password longer that the max length set in the form and end up with an invalid password.
Thanks again
Brian
Thanks again
Brian