|
Chris Grafix - 2006-07-04 00:47:54
Hi,
I am trying to create a password validation with the use of two regular expressions. I am not able to combine both regular expressions into one since I am not using the look-behind operators. This way I need to split the validation into two, one for checking the length and the other to validate a secure password entry. For some reason the form generation class will only validate the second regular expression but not the one for length validation.
<?php
"ValidateRegularExpression"=>"^(.+){8,15}$",
"ValidateRegularExpressionErrorMessage"=>"The Password needs to be between 8 and 15 characters long",
"ValidateRegularExpression"=>"((^[0-9]+[a-zA-Z]+)|(^[a-zA-Z]+[0-9]+))([a-zA-Z0-9]*)$",
"ValidateRegularExpressionErrorMessage"=>"The Password must contain at least 1 character, 1 number, with no special characters",
?>
What seems to be the problem?
Thank you for your consideration and support.
Sincerely
Chris
Manuel Lemos - 2006-07-04 02:34:20 - In reply to message 1 from Chris Grafix
Your second regular expression prevails because in arrays can only have one entry with the same index.
Currently the class will only validate one regular expression.
In theory one regular expression should be sufficient to validate anything. However, some cases may be very complicated to solve with POSIX regular expressions, if possible at all.
I will try to implement support in the next release to specify multiple regular expressions as an array rather than with a single string.
Chris Grafix - 2006-07-05 03:29:27 - In reply to message 2 from Manuel Lemos
Thank you for your response.
So far I have not seen anyone achieve this kind of password validation with one POSIX regular expression. I would appreciate it very much if you could change it into an array in the future.
I have another remark. It might not fit into this thread but I did not wanted to start another one. In your example for replacement expressions:
"ReplacePatterns"=>array("^\\s+"=>"", "\\s+\$"=>""), //remove leading and trailing whitespaces
It most cases it would trim the whitespaces except when I had a string ending with an 's' it would trim off every 's' at the end of the string. I changed it to the basic approach below and it works. Wonder why?
"ReplacePatterns"=>array("^[ ]+"=>"", "[ ]+\$"=>""), //remove leading and trailing whitespaces
Thank you very much for your response and support.
Chris
Manuel Lemos - 2006-07-05 05:19:52 - In reply to message 3 from Chris Grafix
Yes, the latest release is already out, so I will keep in mind to add the feature to make the class validate the values with multiple regular expressions.
As for the replace patterns problem, I could not reproduce the behavior that you describe. I tried Firefox 1.5, Internet Explorer 6, Opera 8.54 and Konqueror 3.4.2 . Which browser have you tried?
Could you have omitted the \ characters from the strings accidentally?
chris lejeune - 2006-07-11 18:01:44 - In reply to message 4 from Manuel Lemos
Hi Manuel,
Thanks for the excellent form class. I'm a do-it-your-selfer, so excuse the non techie jargon.
I'm a Chris too and I came to the forum because ss' were being chopped:
"ReplacePatterns"=>array(
"^\\s+"=>"", /* trim whitespace at the beg */
"\\s+\$"=>"") /* trim whitespace at the end */
By chance, I was typing is some text values and realized the beginning s was being chopped, and then after further testing I realized trailing sssss' were also being chopped.
IE version 6.0.28 using smarty
(By the way, if I create another form object with an existing form object, and want to assign to smarty, will this work:?
$smarty->assign_by_ref("form",$new_object);
{$form} already used in .tpl That puzzles me. :)
Thank You,
Chris
chris lejeune - 2006-07-11 18:11:53 - In reply to message 5 from chris lejeune
The ss are chopped when the form is submitted, like when I'm passing it to another script.
Manuel Lemos - 2006-07-12 18:46:19 - In reply to message 5 from chris lejeune
I have looked into this further and just realized that PHP POSIX regular expression functions to not recognize \s as synonym to white space characters.
Instead, it should be used [[:space:]] . However, most browsers do not recognize that sequence. Therefore, it is recommended to stick to something like [ \t] to represent white space in a way that is a accepted by browsers and PHP.
As for Smarty, that is the right way to assign a reference the form object. Just keep in mind that the forms class plug-in is only ready to handle a single form per template.
|