473,503 Members | 1,747 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regex validation problem

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
Mar 2 '07 #1
7 1667
On Mar 2, 12:58 pm, MattMika <mattm...@hotmail.comwrote:
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

Mar 2 '07 #2
On 2 Mar 2007 13:26:43 -0800, "Larry Marburger" <lm********@gmail.com>
wrote:
>On Mar 2, 12:58 pm, MattMika <mattm...@hotmail.comwrote:
>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
Mar 2 '07 #3
On Mar 2, 4:26 pm, MattMika <mattm...@hotmail.comwrote:
if (!AccessCodeRegxp.test(customers_group_access_code ) {

^^ Missing Closing paranthesis.

Mar 2 '07 #4
On 2 Mar 2007 15:22:11 -0800, sc*************@gmail.com wrote:
>On Mar 2, 4:26 pm, MattMika <mattm...@hotmail.comwrote:
> 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
Mar 3 '07 #5
On Mar 2, 7:26 pm, MattMika <mattm...@hotmail.comwrote:
On 2 Mar 2007 15:22:11 -0800, scripts.cont...@gmail.com wrote:
On Mar 2, 4:26 pm, MattMika <mattm...@hotmail.comwrote:
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
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

Mar 3 '07 #6
On 3 Mar 2007 05:32:51 -0800, "Larry Marburger" <lm********@gmail.com>
wrote:
>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
Mar 5 '07 #7
On Mon, 05 Mar 2007 14:22:06 -0700, MattMika wrote:
On 3 Mar 2007 05:32:51 -0800, "Larry Marburger" <lm********@gmail.com>
wrote:
>>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.
Mar 5 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2373
by: Alan Pretre | last post by:
Can anyone help me figure out a regex pattern for the following input example: xxx:a=b,c=d,yyy:e=f,zzz:www:g=h,i=j,l=m I would want four matches from this: 1. xxx a=b,c=d 2. yyy e=f 3....
1
1693
by: Colin Reid | last post by:
Hey MS, here's an apparent problem in the base class library. I pulled the email validation pattern "^((*)*@(()+(*)*\.)+{2,9})" from http://regexlib.com. If I validate the email address...
2
1844
by: Jan | last post by:
Hi all, I have got the following problem: User fills in excel sheet, this is loaded in Acces. After this I run a validation tool to validate the field formats. One fields is allowed to be...
3
1943
by: Mike | last post by:
I'm trying to have a form where a user has to enter a valid email address, and I'm trying to use the RegEx Validation control to do that. The problem is that when a user submits the form with a...
2
1564
by: Hailstorm | last post by:
How can I control if "a textbox is empty or not" with regex validation? I don't want to use required field validator because I have a masked textbox control and it has "ValidationExpress" property....
4
1352
by: | last post by:
Here is an interesting one. Running asp.net 2.0 beta 2. I have a regular expression used in a regex validator that works on the client side in Firefox but not in IE. Any ideas? IE always reports...
3
3962
by: jab3 | last post by:
Hello. I"m new to this group, and to JavaScript in general, so please forgive me if I breach local etiquette. I'm trying to implement some client-side 'dynamic' validation on a form. I'm having...
1
1929
by: Jim Dornbush | last post by:
Has anyone seen an updated regex expression from Microsoft for the email validation expression so that single quotes are allowed? I've been using the canned regex for emails, but recently been...
10
1849
by: bullockbefriending bard | last post by:
first, regex part: I am new to regexes and have come up with the following expression: ((1|),(1|)/){5}(1|),(1|) to exactly match strings which look like this: 1,2/3,4/5,6/7,8/9,10/11,12 ...
0
7203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7334
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5579
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3156
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1514
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
737
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.