...

View Full Version : problem with arrays



graziano
11-08-2004, 11:41 AM
Hello

I am trying to put a js validation on a username field (inside a login script) .

On a web site I found this code



var __vUsername=new Array(
new Array('0','A','Z','3','a','z','3'),
new Array('1','-','','1','0','9','1','A','Z','1','a','z','1'),
new Array('0','-','','1','0','9','1','A','Z','1','a','z','1'),
new Array('0','-','','5','0','9','5','A','Z','5','a','z','5'),
new Array('0','-','','2','0','9','2','A','Z','2','a','z','2'),
new Array('0','-','','4','0','9','4','A','Z','4','a','z','4'),
new Array('fa',5,0));

function vUsername(fieldvalue) {
return AND_(LE_(fieldvalue.length, 8), validate(__vUsername, fieldvalue));
}


This code is good for me and it checks if the unsername has 5 to 8 caracthers , and check if it starts only with letters .
It's not exactly what I need because I wish modify this array to accept 3 to 8 caracthers (instead of 5 to 8) . The problem is that the array is really hard to understand for me , anyone can help me to modify it to accept 3 to 8 caracthers

Thank you!
Graziano

Willy Duitt
11-08-2004, 11:57 AM
That mess would be hard for anyone to understand...
I'm not going to even bother because I would suggest you trash that and look into using a Regular Expression instead...

A search of these forums should return any number of regular expressions which should be easily modified to fit your needs... I would consider writing one for you but you have not been emphaticly clear on what you need...

But a basic expression which checks that the first character is a letter and the length is 3 to 8 characters would be something like:

var re = /^[a-z]{1}+\w{2,7}$/gi;

.....Willy

graziano
11-08-2004, 12:03 PM
That mess would be hard for anyone to understand...
I'm not going to even bother because I would suggest you trash that and look into using a Regular Expression instead...

A search of these forums should return any number of regular expressions which should be easily modified to fit your needs... I would consider writing one for you but you have not been emphaticly clear on what you need...

But a basic expression which checks that the first character is a letter and the length is 3 to 8 characters would be something like:

var re = /^[a-z]{1}+\w{2,7}$/gi;

.....Willy

I really need to use that code because it use another code and I cannot separate it . Why is it hard to for anyone to understand ? Has it been obfuscated ?

Willy Duitt
11-08-2004, 12:08 PM
I really need to use that code because it use another code and I cannot separate it . Why is it hard to for anyone to understand ? Has it been obfuscated ?

Why is it hard to understand?

It's crap, I can do it in one line of less than 20 characters so why would I bother wasting my time with that BS.... Since you feel that it should not be hard to adapt that to fit your needs... I suppose it should not take you very long to figure it out then...

Good Luck;
.....Willy

jbot
11-08-2004, 12:10 PM
Why is it hard to for anyone to understand ? Has it been obfuscated ?

it's not obfuscated (you wouldn't be able to read it at all if it was). part of it is an array of arrays which tries to mimmick a regular expression. it's just over the top, and hence not immediately apparent what it's trying to do.

RegEx's aren't the easiest thing in the world either, but at least they're a world standard (moreless the same from language to language, too). that way anyone should be able to decipher them, headache pills at the ready if need be.

graziano
11-08-2004, 12:21 PM
to be more clear I am trying to use the login validation available
here

http://cp.demo.psoft.net/psoft/servlet/psoft.hsphere.CP/admin/1_0/psoft.hsphere.CP?template_name=design/logout.html&action=logout

It works fine on my website , but I have only to change the limit from 5 to 3 .


Max length is easy to change to 8 (fieldvalue.length, 8) but
as it seems to change from 5 to 4 I have to change something in array .
I am trying from hours , nothing to do ...

How could be possible that the author dediced to use a so encrypted way ?
Perhaps he used a javascript coder which automatically creates
regex arrays ?

Thank you

Willy Duitt
11-08-2004, 12:23 PM
Oh geesh...

You would think you would take a hint....
Charles told you the same thing as I where you cross-posted your question here (http://www.webdeveloper.com/forum/showthread.php?s=&threadid=48505)....

.....Willy

graziano
11-08-2004, 12:44 PM
Ok I will put in another way . If anyone solve the problem I can pay
via paypal anyone interested ?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum