I like the power of regular expressions if I have the check for certain strings:
I wrote a genaral function RegularExpressionMatch inside a ScriptLibary
Code:
/*****************************************************************************************************
* This function will match a string to a regular expression.
* Author: fid509
* Date: 09/07/2009
* @input {sString,regex} sString:the string to be tested, regex: the regular expression to use
* @output {boolean} true or false to indicate the string matched the regular expression
*
/****************************************************************************************************/
function RegularExpressionMatch(stringToCheck,expression){
if (stringToCheck.match(expression)) {
//print("Valid string");
return true;
}
else {
//print("Invalid string !");
return false;
}
}
Then I can use this function for example in a formatcontrol to set a variable used later on in validations.
Code:
//Check if field gdcode contains a string matching the pattern G9999D999
var re="/^[Gg]{1}\d{4}[Dd]{1}\d{3}$/";
re = eval(re);
if (system.library.FunctionsGlobal.RegularExpressionMatch(system.vars.$file.gdcode,re)) {
system.vars.$validGDcode=true;
//print("Valid GD code");
}
else {
system.vars.$validGDcode=false;
//print("Invalid GD code !");
}
Bookmarks