REGEXP for field validatiopn

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

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

[SIZE=2]example: October 17, 1998, John D Roe - would be 101798JOHDROE*[/SIZE]

[SIZE=2]example: February 29, 2000, Mike Smith - would be 022900MIK*SMIT[/SIZE]

^(?!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

  • 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!?!?!

  • Share my pain, been asking similar for ages http://www.scriptcase.net/forum/forum/scriptcase-8/discussion-aa/69665-how-to-escape-{{-and-}}-in-sc. I figure nobody on the forum knows and it’s not possible in this version of SC hence NetMake’s silence too.

    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:

    
    // you can create this function as a lib and use whenever you need
    function escapeScSpecialSymbols($str){
        return str_replace(
            Array("{ ", "[ "),
            Array("{", "["),
            $str
        );
    }
    
    
    
    // then just call it, passing the string with the text to escape
    echo escapeScSpecialSymbols("{ 20}[ asd]"); // this will return/echo {20}[asd]
    
    

    Hi Mamende, this is very insightful. For my own scenario (http://www.scriptcase.net/forum/forum/scriptcase-8/discussion-aa/66386-escaping-curly-brackets-in-sc-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.

    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…

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

    You’re welcome! :smiley:

    I found another way to work around this issue, maybe it will be useful to someone.

    I used libraries functionality where I created code that would have issues getting phrased by scriptcase, then included the library file and called the function, in my code. Everything worked smoothly

    To do this click on tools, the internal libraries, then create new library if you do not already have one.

    Create function in new file that will run your code.

    Inside your application, go to Programming and Internal Libraries or just libraries, the enable library file you added.

    Now call the function in your code, and it should phrase fine.