Security

last person joined: yesterday 

Forum to discuss Enterprise security using HPE Aruba Networking NAC solutions (ClearPass), Introspect, VIA, 360 Security Exchange, Extensions, and Policy Enforcement Firewall (PEF).
Expand all | Collapse all

Form Validation using arrays

This thread has been viewed 2 times
  • 1.  Form Validation using arrays

    Posted Jan 19, 2015 05:25 AM
    Morning all, I have a query regarding arrays in form validation. I am trying to limit the number of characters in a username as a method of ensuring that devolved administrators are using the correct length. Correct lengths will be number based, with either 5, 6, 14 or 16 characters being allowed. I can get the limiting to work on a single array (ie 5 characters) by using array ( 0 => 10000, 1 => 99999, ) Does anyone know if it is possible to use an OR statement within an array to check the number of characters in our username scenario above? I have tried numerous formats using standard syntax for or (OR, ||, etc) but i cant seem to get it to work. I have even tried using additional variables to the array, such as array ( 0 => 10000, 1 => 99999, 2 => 100000, 3 => 999999, ) but again this fails. TIA Gordie


  • 2.  RE: Form Validation using arrays
    Best Answer

    EMPLOYEE
    Posted Jan 20, 2015 05:40 AM

    Gordie,

     

    I did some testing, and you may better use the IsRegexMatch validator for this purpose with the following Regex:

     

    ^\d\d\d\d\d$|^\d\d\d\d\d\d$|^\d\d\d\d\d\d\d\d\d\d\d\d\d\d$|^\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d$

     

    So this is ^\d\d\d\d\d$ => string that has exact 5 digits (\d) between the start of line (^) and the end ($); or (|) the same with 6, 14 or 16 digits.

     

    Got how to create this validator from: http://www.cs.tut.fi/~jkorpela/perl/regexp.html

     

    I'm quite sure that Regex Gurus can squeeze this into a much smaller regex; I'm not that experienced.

     

    Regards, Herman



  • 3.  RE: Form Validation using arrays

    Posted Jan 26, 2015 11:24 AM
    Hi Herman,

    Sorry for the delay, I have not been about to reply.

    I will try this later this week and will provide feedback to its success

    Now all I have to do is remember how the wonderful world of regex works :)

    Thanks

    G


  • 4.  RE: Form Validation using arrays

    Posted Jan 27, 2015 03:27 AM
    Thanks Herman,

    Perfect

    I dug out my old O'reillys pocket regex book and have implemented the following

    ^\d{5}$|^\d{6}$ etc, replacing all of the d's with a \d{n} where n is the number of characters that you want the pattern to match

    #happy_days :)

    Thanks again

    Gordie