Announcement

Collapse
No announcement yet.

REGEXP for field validatiopn

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • REGEXP for field validatiopn

    I have a complex formatted field to validate that I use REGEXP to validate normally.

    MM=Month
    DD=Day
    YY=Year
    FFF= First three letters of the first name (* is used to fill empty spaces)
    I=Middle initial (* if not specified)
    LLLL= First 4 letters of last name (* is used to fill empty spaces)

    example: October 17, 1998, John D Roe - would be 101798JOHDROE*

    example: February 29, 2000, Mike Smith - would be 022900MIK*SMIT


    ^(?!023)(?!0229.[13579])(?!0229[02468][26])(?!0229[13579][048])(?!(0[469]|11)31)(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])([0-9]{2})(?!.?[*][^*])([a-zA-Z*]{3})[a-zA-Z*](?!.{0,2}[*][^*])([a-zA-Z*]{4})$

    Being new to scriptcase, how do I implement a REGEXP validation inside scriptcase?

    Thanks
    Last edited by John Coombs; 06-03-2016, 10:49 AM.

  • #2
    BUMP!!!

    $tst = {USSNumber};
    $regex = "^(?!023)(?!0229.[13579])(?!0229[02468][26])(?!0229[13579][048])(?!(0[469]|11)31)(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])([0-9]{2})(?!.?[*][^*])([a-zA-Z*]{3})[a-zA-Z*](?!.{0,2}[*][^*])([a-zA-Z*]{4})$";

    If (!preg_match($regex,$tst) {
    sc_error_message('Please enter the right value');
    }

    I have tried this bu I believe the error is related to the curly brackets [ {} ]!!! How do I specify the { and } in a regular expression to get validation to work!?!?!

    Comment


    • #3
      Share my pain, been asking similar for ages http://www.scriptcase.net/forum/foru...d-%7D%7D-in-sc. I figure nobody on the forum knows and it's not possible in this version of SC hence NetMake's silence too.

      Comment


      • #4
        Hi there!

        It seems like Scriptcase replaces every single {some value} or [some value] whenever it finds, even before our code runs. And I don't see any oficial way to solve that.

        But analysing this case today, I found a workaround. If you put a character (except for letters/numbers) right after the opening character "[" or "{", Scriptcase won't replace it. So you could just put a space character, and then have a function to escape that. And because Scriptcase doesn't parse it recursively, it will stick as it is. Something like this:

        Code:
        // you can create this function as a lib and use whenever you need
        function escapeScSpecialSymbols($str){
            return str_replace(
                Array("{ ", "[ "),
                Array("{", "["),
                $str
            );
        }
        Code:
        // then just call it, passing the string with the text to escape
        echo escapeScSpecialSymbols("{ 20}[ asd]"); // this will return/echo {20}[asd]
        SC Tools: A browser extension to make working with ScriptCase simpler and even more productive.

        http://blog.andersonmamede.com.br

        Comment


        • #5
          Hi Mamende, this is very insightful. For my own scenario (http://www.scriptcase.net/forum/foru...c-s-sql-macros) I don't believe it will work though because the output of the function will still be passed into sc_exec_sql macro.

          Comment


          • #6
            Hi scriptcaser! I've just tested that regexp using 'escapeScSpecialSymbols' and the macros 'sc_exec_sql' and 'sc_lookup', and in both cases it has worked. Hasn't it worked for you?

            It seems, to me, that ScriptCase only parses our code once at the beginning of the process and then leaves it "as is". So, in theory, this workaround should work for you too...
            SC Tools: A browser extension to make working with ScriptCase simpler and even more productive.

            http://blog.andersonmamede.com.br

            Comment


            • #7
              Oh that should be correct: the macros are changed by a preprocessor not the run-time engine. Super! Thanks a lot.

              Comment


              • #8
                You're welcome!
                SC Tools: A browser extension to make working with ScriptCase simpler and even more productive.

                http://blog.andersonmamede.com.br

                Comment

                Working...
                X