For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > June 2004 > RE: [PHP-DB] regular expression help









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author RE: [PHP-DB] regular expression help
Matthias steinböck

2004-06-24, 3:55 pm

hi!

is this correct: you want to check if there are two letters in the
password wich do not surround a digit? if so this is what you need:

<?php

// dies
$password = 'alfgoesswimming';
// dies too
$password = 'a2lf4g2o4e7s9s3w9i0m5m7i0n3g';
// survives
$password = 'a2l5f4g2o4e7s9s3w9i0m5m7i0n3g';


$found = array();

$pattern = '#[a-z_]{2}#i';

if(preg_match_all($pattern, $password, $found)>0) {
die('You must have a number between 2 letters in your password ... 0-9');
} else {
die('password accepted');
}

?>


greez ma
Matthias steinböck

2004-06-24, 3:55 pm

ok... this still does not do what you want, because it does not consider
that only digits should be between the letters... here is the correct
solution:

<?php

// dies
$password = 'alfgoesswimming';
// dies too
$password = 'a2lf4g2o4e7s9s3w9i0m5m7i0n3g';
// survives
$password = 'a2$5l5f4g2o4e7s9s3w9i0m5m7i0n3g';


$found = array();

$pattern = '#[^0-9]{2}#i';

if(preg_match_all($pattern, $password, $found)>0) {
die('You must have a number between 2 letters in your password ... 0-9');
} else {
die('password accepted');
}

?>

hth greez ma

Matthias Steinböck wrote:

> hi!
>
> is this correct: you want to check if there are two letters in the
> password wich do not surround a digit? if so this is what you need:
>
> <?php
>
> // dies
> $password = 'alfgoesswimming';
> // dies too
> $password = 'a2lf4g2o4e7s9s3w9i0m5m7i0n3g';
> // survives
> $password = 'a2l5f4g2o4e7s9s3w9i0m5m7i0n3g';
>
>
> $found = array();
>
> $pattern = '#[a-z_]{2}#i';
>
> if(preg_match_all($pattern, $password, $found)>0) {
> die('You must have a number between 2 letters in your password ...
> 0-9');
> } else {
> die('password accepted');
> }
>
> ?>
>
>
> greez ma
>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com