string validation using freemarker - freemarker

I have a text like this "please list TK 3-ASDFGVB"
I need to validate this text using freemarker with following scenarios.
- In text make sure , After TK "3-ASDFGVB" should present.
- "3-ASDFGVB" should contain total 9 character.
- "3-ASDFGVB" make sure "-" present between 3 and ASDFGVB
Tried the scenario's with below code.
TKNumberstr="please list TK 3-ASDFGVB"
{TKNumberstr.value?matches('.*([0-3]-[0-9]{9}).*')?then('match','nomatch')}
If the validation match then i will continue with next process. Need help to validate the rule

Try something along these lines:
<#assign text = "please list TK 3-ASDFGVB" >
<#assign targets = text?split("TK ") , target = targets[1]>
${(target?length == 9 && target?index_of("-")==1)?then('match','nomatch')}
You should get match as output.
Edit: as per comment below:
${((TKNumberstr?split("TK ")[1])?length== 9 && TKNumberstr?split("TK ")[1]?index_of("-")==1)?then('match','nomatch')}

Related

If results are not >= "Number" then show blank

New to building Crystal Reports and SQL.
I'm trying to write a script to where if results is >= 12.1 then show result else show no results.
Same goes for the <=9.9.
Here is what I have so far:
if {Test.Name} = "xyz" and {TestResults.numresult}>= 12.1 then {TestResults.numresult} else "";
Below is an image showing the same results across the board. I just want the results to show when its <=9.9 or >=12.1.
Hope this make sense.
Your statement returns a number from one branch and a string from the other. It must return the same data type.
One option is to use a True/False expression in a Suppress expression.
Another option is to return a zero in the other branch and use number formatting to suppress if zero (it's a built-in option for numbers).
Another option is to modify your expression so it returns a string from both branches. For example:
if {Test.Name} = "xyz" and {TestResults.numresult}>= 12.1 then ToText({TestResults.numresult}, 1, ",") else "";
The 1 argument requests 1 decimal point. The "," argument requests a comma as thousands separator. You can adjust those to match your number formatting requirements.

Autocad Diesel IF expression for sheet number tag

I am trying to automate a sheet tag with a Diesel expression in AutoCad.
This gets me the twelfth character in the drawing name. But as soon as I get to sheet 10 this will say its sheet 0.
$(substr,$(getvar,dwgname),12,1)
Does anyone know a way to get an If statement to see if the eleventh character is a 0 then run the above code else run $(substr,$(getvar,dwgname),11,2)
This is something i have tried.
$(IF,substr,$(getvar,dwgname),11,1)="0"$(substr,$(getvar,dwgname),11,2,substr,$(getvar,dwgname),12,1)
This appears to be similar to excel formulas. Thanks for any help.
The format for the Diesel if statement is:
$(if, expr, dotrue [, dofalse])
If the expr is nonzero, it evaluates and returns dotrue.
You seem to have a lot more going on in your sample. Do the full evaluation (does the 11th character equal 0 in the expr portion and then set your returns, the false portion is optional and can be omitted.
Here is the Diesel expression i got working for auto sheet no. in autocad fields.
$(if,$(substr,$(getvar,dwgname),11,1)"0",$(substr,$(getvar,dwgname),11,2),$(substr,$(getvar,dwgname),12,1))
$(if,$(substr,$(getvar,dwgname),11,1)"0" = Does character 11 = 0
,$(substr,$(getvar,dwgname),11,2) = if no then take character 11 and the next char.
,$(substr,$(getvar,dwgname),12,1)) = if char 11 is = to 0 then take only char 11.
I use two fields in my autocad border. One for the filename without the sheet no and this one for only the sheet number.
Example filename: A150225_S001.dwg
$(substr,$(getvar,dwgname),1, 7) = Use char from position 1 to 7. "A150225"
$(if,$(substr,$(getvar,dwgname),11,1)"0",$(substr,$(getvar,dwgname),11,2),$(substr,$(getvar,dwgname),12,1)) = Use sheet no. at end of filename string. "1"
Hope this helps anyone looking to do something similar.

Visual Studio 2012 Form1.vb user input validation

I have connected the sql database to my vb project and the last feature I need is to validate the user input. Two of the textboxes needs to be validated when adding a new record.
txtName is the first textbox that consists of the following format: BCO103/T1/01 . 'BCO' will always stays the same, however the rest needs to be input by the user. Letters and numbers needs to stay in exact the same place.
txtModuleID is the second textbox that needs to be validated. The data for this field looks like this: BCO120 . Yet again, BCO will always stay the same, however the 3-digit number will change.
Im sure you can use substrings for this
for example:
If txtModuleID.Text.Substring(0,2) = "BCO" And txtModuleID.Text.Substring... etc Then 'add other conditionals
blnValidated = True
Else
blnValidated = False
End If
If txtModuleID.Text.Trim.ToUpper().SubString(0,2).equals("BCO") and len(txtModuleID.Text.Trim) = 6 Then
If txtModuleID.Text.Trim.SubString(3,5).isNumeric() Then
//valid input
Else
//message prompt that last 3 digits of the input is not numeric
End If
Else
//message prompt that input has invalid format and that input must start with BCO
End IF
Substring (0, 2) means from 0 until 2... getting the sub string of the input with letters in index 0, 1 and 2. The rest follows.
As for the first input, please do expound. I didn't quite catch how you want it to be validated.

ReportViewer Expressions , character check

I'd like to know if there is a way to check if there is a comma , in the !field.Value.
I want to make these conversations:
10,5 -> 10,50
900 -> 900,00
To do that, I need to know if there is a comma in the field value and also how many characters are after the comma. Is it possible ?
Look at InStr(), Len(), and IIF(), I think they will get you what you want.
I don't have a way to test this where I am, but basically I think this expression will get you there:
=IIF(InStr(Fields!MyField.Value, ",") > 0,
Fields!MyField.Value & LEFT("000000", (-1 *(2 - (Len(Fields!MyField.Value) - InStr(Fields!MyField.Value, ","))))),
Fields!MyField.Value & ",00")
Here's the basic idea of the script:
If there is a comma in the field,
then add x number of 0s onto the end of the field
where x is 2 - (the length of the field - the position of the ',' in the string) * -1
else just return the field + ",00"

Ruby replace text within single quotes or backticks for html tag

Hello I am trying to build a simple action in Ruby that takes one string like
result = "This is my javascript variable 'var first = 1 + 1;' and here is another 'var second = 2 + 2;' and that's it!"
So basically I would like to take the text within single quotes ' or backticks ` and and replace it by:
<code>original text</code> note I'm replacing it by an opening and closing code tag
Just like in markdown
so I would have a result like
result = "This is my javascript variable <code>var first = 1 + 1;<code> and here is another <code>var second = 2 + 2;</code> and that's it"
If it's possible to run this natively without the need of any extra gem it would be great :)
Thanks a lot
I guess you'll need to iterate the string and parse it. While you can do non-greedy regex matches, e.g. result.gsub!(/'([^']*)'/, '<code>\1</code>') you might find the result might not behave correctly in corner-cases.
Without any other advanced requirement
>> result.gsub(/\s+'/,"<code>").gsub(/'\s+/,"</code>")
=> "This is my javascript variable<code>var first = 1 + 1;</code>and here is another<code>var second = 2 + 2;</code>and that's it!"
You will need to come-up with a character as a delimiter for your code, which you don't use otherwise..
Why? because of all the corner cases. E.g. the following string
result = "This's my javascript variable 'var first = 1 + 1;' and here is another 'var second = 2 + 2;' and that's it!"
which would otherwise produce:
"This<code>s my javascript variable </code>var first = 1 + 1;<code> and here is another </code>var second = 2 + 2;<code> and that</code>s it!"
Total garbage out..
However if you use a unique character as a delimiter that's otherwise not used, you can create a non-greedy RegExp which will do the search/replace
e.g. using a # character to delimit the code:
"This's my javascript variable #var first = 1 + 1;# and here is another #var second = 2 + 2;# and that's it!"

Resources