Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Character limit

Posted on 2003-11-16
7
Medium Priority
?
406 Views
Last Modified: 2013-12-03
Hi,

I need a script that will check if a variable is 7 characters long or else spit out an error. This is just for the sign up password value on my site, since i dont want peaple getting their account stolen so easy.

Also, I tried this out and was wondering if you could tell me why it doesnt work.

if (!preg_match("/.*.*.*.*.*.*.*/", $_POST['passwd'])) {
            echo('Password needs to be 7 characters long.');
            include('register.html');
            exit();
      }


Thanks.
0
Comment
Question by:TaintedGod
  • 4
  • 2
7 Comments
 
LVL 19

Accepted Solution

by:
Michael701 earned 250 total points
ID: 9758811
if strlen('passwd')<7) {
            echo('Password needs to be 7 characters long.');
            include('register.html');
            exit();
      }

I assume you want 7 or more characters. if you really want every password to be exactly 7 characters then change the < to ==

0
 
LVL 6

Expert Comment

by:mattjp88
ID: 9758866
Well, you could do this with javascript.  In the <input> tag, just put maxlength=7, that will prevent users from entering a longer password.  So this is what your <input> tag would oook like:

<input type="password" maxlength="7" name="password">

-Matt
0
 
LVL 2

Author Comment

by:TaintedGod
ID: 9759361
Michael701

Before i even try this code i can tell there is an error in there, and since ive never used this function before im not sure where the brackets go, please look this over. Thanks.

mattjp88

Thanks for the post but, i did post this question in the PHP section and not in Javascript.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:TaintedGod
ID: 9759416
Ah nevermind, i fixed it myself......It should of been:

if (strlen($_POST['passwd'] < 7)) {
             echo('Password needs to be 7 characters long.');
             include('register.html');
             exit();
      }

Thanks anyways.
0
 
LVL 2

Author Comment

by:TaintedGod
ID: 9759490
That's odd.....I dont get an error message but I get my echo message everytime.
0
 
LVL 19

Expert Comment

by:Michael701
ID: 9759965
you miss placed a )

if (strlen($_POST['passwd']) < 7) {
             echo('Password needs to be 7 characters long.');
             include('register.html');
             exit();
      }

Thanks anyways
0
 
LVL 2

Author Comment

by:TaintedGod
ID: 9760086
That looks better :P
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question