[SOLVED] eregi expression

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

[SOLVED] eregi expression

Post by gurjit »

hi

how can i say that a sequence following the alphabet is rejected.

for example

abcdefghijklmnopqrstuvwxyz (rejected)

so if i put

abcdefgh (rejected)
fghijklmnopqrs (rejected)
pqrstuvwx (rejected)
bournemouth (accepted)


the input will be 8 to 12 characters
Last edited by gurjit on Wed Jun 13, 2007 9:25 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Please define this "sequence."
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

Post by gurjit »

if anyone types in lets say

abcdefghijklmnopqrstuvwxy

from any part of the alphabet as

abcdefgh
abcdefghi
bcdefghijk
ijklmnopqr
mnopqrstuv

then it should be rejected.

however if they type
aabcdefgh
abbcdefgh
bccdefghijk

its is still accepted

The user will be able to type in any word between 8 and 12 chars

as long as the user does not enter a complete string of the alphabet as it is "abcdefghijklmnopqrstuvwxy".

hope this makes sense

what i'm trying to do is something like internet banking. the user creates a memorable word between 8 and 12 chars. At login the user is asked to recall 2 letters from there word. The 2 letters are random. (this part of the code is done. What I cant do is find a way to ensure users dont use a simple word like "abcdefgh" or "lmnopqrst".
Last edited by gurjit on Tue Jun 12, 2007 9:04 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You're not looking for a regular expression. What you want is basic math in a series.
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

Post by gurjit »

what i'm trying to do is something like internet banking. the user creates a memorable word between 8 and 12 chars. At login the user is asked to recall 2 letters from there word. The 2 letters are random. (this part of the code is done. What I cant do is find a way to ensure users dont use a simple word like "abcdefgh" or "lmnopqrst".

how can i check for any weak combinations
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

First thing coming to my mind: Compare the sequence of character from left to right (for/while loop with (int)$char{$n}), the current character with the next and see if the next one is 1 number greater than the current. If it isn't, set $accepted to true and allow the input if $accepted has been set to true at some point.
Only works for A-Z and a-z though, no foreign letters.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

<?php
$haystack = 'abcdefghijklmnopqrstuvwxyz';

$tests = array(
	'abcdefgh',
	'abcdefghi',
	'bcdefghijk',
	'ijklmnopqr',
	'mnopqrstuv',
	'aabcdefgh',
	'abbcdefgh',
	'bccdefghijk'
);

foreach($tests as $needle) {
 $accepted = false===strpos($haystack, $needle);
 echo $needle, ' ', $accepted ? 'accepted' : 'rejected', "<br />\n";
}
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Ahh the beauty of simplicity.
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

Post by gurjit »

A BIG THANKS volka


WORKED LIKE A BEAUTY
Post Reply