|
Posted by gosha bine on 05/07/07 16:42
Michael Fesser wrote:
> .oO(adzir)
>
>> I need to validate password keyed in by the system users so that the
>> password will contain only letters and numbers plus at least one
>> capital letter. Exclude these symbols
>>
>> , < > ? / * ( ) & ^ % $ # ! ~ ` " '
>>
>> this is my code:
>>
>> ereg("[A-Za-z0-9[^\,\<\>\?\/\*\(\)\&\^\%\$\#\!\~\`\"\']]+$", $str)
>>
>> am i correct?
>
> Way too complicated and using the old deprecated ereg* functions.
>
> If the PW should only contain letters and digits, then use a pattern
> that matches for exactly that:
>
> preg_match('#[A-Z\d]+#i', $str);
>
> If there has to be a capital letter somewhere in the PW, then try a
> combination like this:
>
> preg_match('#[a-zA-Z\d]*[A-Z][a-zA-Z\d]*#', $str);
>
> HTH
> Micha
Michael, your pattern will also match "*&(*%& Z #)&*(", because it's not
anchored. Use ^ and $ (and not forget /D) to make it do what you want.
--
gosha bine
extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
Navigation:
[Reply to this message]
|