Solved

Character limit

Posted on 2003-11-16
7
392 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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 dynamically set the form action using jQuery.

623 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