Page 1 of 1

[SOLVED] eregi expression

Posted: Tue Jun 12, 2007 6:16 am
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

Posted: Tue Jun 12, 2007 8:52 am
by feyd
Please define this "sequence."

Posted: Tue Jun 12, 2007 8:59 am
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".

Posted: Tue Jun 12, 2007 9:02 am
by feyd
You're not looking for a regular expression. What you want is basic math in a series.

Posted: Tue Jun 12, 2007 9:05 am
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

Posted: Tue Jun 12, 2007 10:43 am
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.

Posted: Tue Jun 12, 2007 2:33 pm
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";
}

Posted: Tue Jun 12, 2007 2:58 pm
by Benjamin
Ahh the beauty of simplicity.

Posted: Wed Jun 13, 2007 9:23 am
by gurjit
A BIG THANKS volka


WORKED LIKE A BEAUTY