Connecting Tech Pros Worldwide Help | Site Map

Regex validation problem

  #1  
Old March 2nd, 2007, 06:15 PM
MattMika
Guest
 
Posts: n/a
Can anyone point out the problem with this? The commented regex var
and if statement dont work and break the GroupName check when
uncommented. I tested the AccessCodeRegxp with preg_match and it seems
to work fine, it just wont here. Any pointers would be great.

<script language="javascript"><!--
function check_form() {
var error = 0;
var error_message = "<?php echo JS_ERROR; ?>";
var customers_group_name =
document.customers.customers_group_name.value;
var customers_group_access_code =
document.customers.customers_group_access_code.val ue;

var GroupNameRegxp = /^([0-9a-zA-Z]+){8,32}$/;
/* var AccessCodeRegxp =
/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*]).{6,12}$/;*/
if (!GroupNameRegxp.test(customers_group_name)) {
error_message = error_message + "<?php echo
ERROR_CUSTOMERS_GROUP_NAME.'\n'; ?>";
error = 1;
}

/* if (!AccessCodeRegxp.test(customers_group_access_code ) {
error_message = error_message + "< ?php echo
ERROR_CUSTOMERS_GROUP_ACCESS_CODE; ?>";
error = 1;
}*/

if (error == 1) {
alert(error_message);
return false;
} else {
return true;
}
}
//--></script>
Matt Mika

"These animals evacuate ethyl alcohol from their bowels and carbon dioxide from their urinary organs. Thus, one can observe how a specially lighter fluid is exuded from the anus and rises vertically whereas a stream of carbon dioxide is ejected at very short intervals from enormously long genitales."

Justus Freiherr von Liebig - 1839
  #2  
Old March 2nd, 2007, 09:35 PM
Larry Marburger
Guest
 
Posts: n/a

re: Regex validation problem


On Mar 2, 12:58 pm, MattMika <mattm...@hotmail.comwrote:
Quote:
Can anyone point out the problem with this? The commented regex var
and if statement dont work and break the GroupName check when
uncommented. I tested the AccessCodeRegxp with preg_match and it seems
to work fine, it just wont here. Any pointers would be great.
Matt,

Could you post the string you're trying to match with AccessCodeRegxp?

--
Larry

  #3  
Old March 2nd, 2007, 10:45 PM
MattMika
Guest
 
Posts: n/a

re: Regex validation problem


On 2 Mar 2007 13:26:43 -0800, "Larry Marburger" <lmarburger@gmail.com>
wrote:
Quote:
>On Mar 2, 12:58 pm, MattMika <mattm...@hotmail.comwrote:
Quote:
>Can anyone point out the problem with this? The commented regex var
>and if statement dont work and break the GroupName check when
>uncommented. I tested the AccessCodeRegxp with preg_match and it seems
>to work fine, it just wont here. Any pointers would be great.
>
>Matt,
>
>Could you post the string you're trying to match with AccessCodeRegxp?
I've been trying all kinds of combinations. This is for a form on our
customer groups admin page on our ecommerce site. The idea is to have
our people create 'access codes' that arent real easy to guess when
creating new customer groups, ie. a string 6 to 12 chars in length,
that contains one number, one lowercase letter, one uppercase letter,
and one special character - !, @, #, $, %, ^, & or *

valid codes:
@tHom3
123$aBCD
ThisCod3!
AppleC@re22
As*ixs3

I should've only posted the code below as the groupname stuff works
fine by itself, it only breaks when this 'access code' regex is
present. I've been unable to get the 'access code' regex to check
properly even though the regex works fine in preg_match.

function check_form() {
var error = 0;
var error_message = "<?php echo JS_ERROR; ?>";
var customers_group_access_code =
document.customers.customers_group_access_code.val ue;

var AccessCodeRegxp =
/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*]).{6,12}$/;

//alert(customers_group_access_code);
if (!AccessCodeRegxp.test(customers_group_access_code ) {
error_message = error_message + "<?php echo
ERROR_CUSTOMERS_GROUP_ACCESS_CODE; ?>";
error = 1;
}

if (error == 1) {
alert(error_message);
return false;
} else {
return true;
}
}

I can see the form input with alert(customers_group_access_code);, but
this will not return an error if the code does not comply with the
regex or even when its empty.
TIA
Matt Mika
  #4  
Old March 2nd, 2007, 11:35 PM
scripts.contact@gmail.com
Guest
 
Posts: n/a

re: Regex validation problem


On Mar 2, 4:26 pm, MattMika <mattm...@hotmail.comwrote:
Quote:
if (!AccessCodeRegxp.test(customers_group_access_code ) {

^^ Missing Closing paranthesis.



  #5  
Old March 3rd, 2007, 12:45 AM
MattMika
Guest
 
Posts: n/a

re: Regex validation problem


On 2 Mar 2007 15:22:11 -0800, scripts.contact@gmail.com wrote:
Quote:
>On Mar 2, 4:26 pm, MattMika <mattm...@hotmail.comwrote:
Quote:
> if (!AccessCodeRegxp.test(customers_group_access_code ) {
>
>
>^^ Missing Closing paranthesis.
>
>
Sure enough! jeez...

Getting something out of it now, unfortunately it wont match unless my
characters are in the order they are in the regex :(

/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*]).{6,12}$/
ie. digit, lowercase, uppercase, special

Wonder why it doesnt do that in preg_match? Any differences between
how preg_match and js interpret regex I should know about?

Thanks
Matt Mika
  #6  
Old March 3rd, 2007, 01:45 PM
Larry Marburger
Guest
 
Posts: n/a

re: Regex validation problem


On Mar 2, 7:26 pm, MattMika <mattm...@hotmail.comwrote:
Quote:
On 2 Mar 2007 15:22:11 -0800, scripts.cont...@gmail.com wrote:
>
Quote:
On Mar 2, 4:26 pm, MattMika <mattm...@hotmail.comwrote:
Quote:
if (!AccessCodeRegxp.test(customers_group_access_code ) {
>
Quote:
^^ Missing Closing paranthesis.
>
Sure enough! jeez...
>
Getting something out of it now, unfortunately it wont match unless my
characters are in the order they are in the regex :(
>
/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*]).{6,12}$/
ie. digit, lowercase, uppercase, special
>
Wonder why it doesnt do that in preg_match? Any differences between
how preg_match and js interpret regex I should know about?
>
Thanks
Matt Mika
Matt,

I just tried the following code and it works fine for me.

var re = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*]).{6,12}$/;
alert(re.exec("aA@3ab"));
alert(re.test("aA@3ab"));

I didn't try all your code, but the regex should be fine. Go simpler
with your code and see if it really in the regex that's not working
properly.

--
Larry

  #7  
Old March 5th, 2007, 09:35 PM
MattMika
Guest
 
Posts: n/a

re: Regex validation problem


On 3 Mar 2007 05:32:51 -0800, "Larry Marburger" <lmarburger@gmail.com>
wrote:
Quote:
>I just tried the following code and it works fine for me.
>
>var re = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*]).{6,12}$/;
>alert(re.exec("aA@3ab"));
>alert(re.test("aA@3ab"));
>
>I didn't try all your code, but the regex should be fine. Go simpler
>with your code and see if it really in the regex that's not working
>properly.
Thanks guys.

Turns out IE7 was the problem(besides the missing parenthesis). Larrys
exec and test code returned null and false so I finally checked
another browser. FireFox and Netscape both do fine with your code and
mine. I'll have to find a machine here running IE6 and see what it
does...

Are there any resources out there that might help me to figure this
out or am I pretty much screwed in IE7? If so I'll probably just scrap
this and generate a access code with no user input allowed...

Thnx,
Matt Mika
  #8  
Old March 5th, 2007, 09:55 PM
Ivan Marsh
Guest
 
Posts: n/a

re: Regex validation problem


On Mon, 05 Mar 2007 14:22:06 -0700, MattMika wrote:
Quote:
On 3 Mar 2007 05:32:51 -0800, "Larry Marburger" <lmarburger@gmail.com>
wrote:
>
Quote:
>>I just tried the following code and it works fine for me.
>>
>>var re = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*]).{6,12}$/;
>>alert(re.exec("aA@3ab"));
>>alert(re.test("aA@3ab"));
>>
>>I didn't try all your code, but the regex should be fine. Go simpler
>>with your code and see if it really in the regex that's not working
>>properly.
>
Thanks guys.
>
Turns out IE7 was the problem
That doesn't surprise me.

I've seen sites that render exactly the same in IE6, Firefox and Opera
that don't render correctly in IE7... it's a pretty easy assumption that
client-side coding is broken too.
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Validation Problem Using Regex Phillip Vong answers 2 October 4th, 2006 12:55 PM
Regex validation problem Rasika WIJAYARATNE answers 3 June 26th, 2006 11:45 AM
regex problem - 2.0 beta 2 answers 4 November 19th, 2005 04:47 PM
RegEx Validation Control Bug?? Mike answers 3 November 18th, 2005 01:15 AM