Solved

Character limit

Posted on 2003-11-16
7
364 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 125 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
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

803 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