IMPORTANT NOTICE: As of 21 February, anything posted in this community WILL NOT BE MIGRATED to our new community site. We have pulled all user information and data from this site and are now in an approximately week long process of importing users, roles, and data to our new site. We are leaving this site open and active so you can post and hopefully get a response until the migration is complete. Once complete, the URL that currently takes you to this site will take you to our new site so your bookmarks will work as always. Please read the information on a New Login Process
[-] boolean VerifyStringPattern(String sPattern, String sMask) [ ] //The boolean value to evaluate the pattern match [ ] boolean retVal = false [ ] [ ] //get the left-most character of the mask file, are we looking [ ] //for a digit? [-] if(Left(sMask,1) == "d") [ ] //if we are looking for a digit, is the left-most character of [ ] //the sPatter string a digit [-] if(IsDigit(Left(sPattern,1))) [ ] //Yes, evaluate to true [ ] retVal = true [ ] //No, we are looking for either an alphabetic character or a [ ] //specific pattern character [-] else [ ] //Are we looking for an alphabetic character [-] if(Left(sMask,1) == "a") [ ] //Yes, Is the left-most character of the sPattern string an [ ] //alphabetic character [-] if(IsAlpha(Left(sPattern,1))) [ ] //Yes, Evaluate to true [ ] retVal = true [ ] //No, We are looking for a specific pattern character [-] else [ ] //Does the left-most character of sPattern match the [ ] //pattern character in the mask file [-] if(Left(sPattern,1) == Left(sMask,1)) [ ] //Yes, evaluate to true [ ] retVal = true [ ] [ ] //left-most character is now evaluated, strip the sPattern and [ ] //sMask strings of their left-mostcharacter and check that [ ] // the next character in sPattern conforms to the mask string [-] if(retVal == true && Len(sPattern) != 1) [ ] //if at any stage a character does not conform to the mask [ ] //pattern, evaluate to false [-] if(!VerifyStringPattern(Right(sPattern,Len(sPattern)-1), Right(sMask,Len(sMask)-1))) [ ] retVal = false [ ] [ ] //return the evaluation of this function [ ] return retVal
In the above function, the "sPattern" argument is the string variable you pass to the function to verify if it conforms to a specific pattern. The "sMask" argument is the string variable that contains the pattern that you want to match the "sPattern" function to, the "sMask" argument must take a format such as the following examples:
In the above examples, the "a" specifies that this character must be an alphabetic character, the "d" specifies that the character must be a digit. You can also specify other characters within your pattern and the function will evaluate if that character appears in the string you wish to verify.
The below demonstrates a testcase which implements the use of the VerifyStringPattern function:
[-] testcase StringPattern() appstate none [-] if(VerifyStringPattern("abc-123","aaa-ddd")) [ ] print("Pattern Matched") [-] else [ ] print("Pattern Mismatch") [ ]