Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Nov 2004
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy problem with arrays

    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

    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

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #3
    New Coder
    Join Date
    Nov 2004
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Willy Duitt
    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 ?

  • #4
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by graziano
    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

  • #5
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by graziano
    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.
    *keep it simple (TM)

  • #6
    New Coder
    Join Date
    Nov 2004
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts
    to be more clear I am trying to use the login validation available
    here

    http://cp.demo.psoft.net/psoft/servl...&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

  • #7
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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....

    .....Willy

  • #8
    New Coder
    Join Date
    Nov 2004
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok I will put in another way . If anyone solve the problem I can pay
    via paypal anyone interested ?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •