I have a regex in my dashboard that performs the validation whether the input value in the field is Numeric or Not. The code/regex works perfectly well.
I need some help in modifying the particular regex so that it should also check if the input field contains any special character such as " <double quote> or <space> at the starting or ending or middle of the string (Basically Padding, Spacing or quotes), That would really help.
The regex that I have which only checks numeric is as follows. It is under the if(match(value ...section , Highlighted in Bold
=================================================
<input type="text" token="selText">
<label>Enter Only Digits</label>
<change>
<eval token="validationResult">if(match(value, "^[0-9]+$"), "Numeric", "Not Numeric")</eval>
</change>
</input>
</fieldset>
================================================================================
It looks like classes aren't recognised here try it this way
<eval token="validationResult">if(match(value, "[^a-zA-Z0-9]"), "Punctuation or space", "Not Punctuation or space"</eval>
Try something like this
<eval token="validationResult">if(match(value, "^[0-9]+$"), "Numeric", if(match(value, "[[:punct:] ]"), "Punctuation or space", "Not Numeric"))</eval>
I tried to test it , whether the input value in the text box has " <quotation Mark> or space padded anywhere in the beginning or end , But it's not working.
It's rather giving me "malformed expression in eval".
<input type="text" token="selText">
<label>Don't enter any Splunk Un-escapable characters</label>
<change>
<eval token="validationResult">if(match(value, "[[:punct:] ]"), "Punctuation or space", "Not Punctuation or space"</eval>
</change>
</input>
</fieldset>
==========================
When I tried to input this 22"455"
Instead of getting the validation command , I see this "Error in 'eval' command: The expression is malformed."
It looks like classes aren't recognised here try it this way
<eval token="validationResult">if(match(value, "[^a-zA-Z0-9]"), "Punctuation or space", "Not Punctuation or space"</eval>
Thank you @ITWhisperer , It's almost perfect. Just a minor issue.
Issue : When I input any string or number with padded spaces in front or back it gives that warning, also it gives warning when I enter slash (/) , which is just perfect. The problem occurs, when I input a quotation sign, example NewYork" or "New"York , then it throws error and says "Unbalanced quotes". Also, is there a way we can only validate if the space is in the beginning or end ? currently if the space is between strings it's showing validation message too. example: New<space>Yoork
Thank you so much for your help. I'm pasting the entire dashboard code snippet for your reference.
===============================================================
<form>
<label>TextBox Validation</label>
<fieldset submitButton="false">
<input type="text" token="selText">
<label>Enter your Input (Do not add splunk special charachters that cannot be escaped)</label>
<change>
<eval token="validationResult">if(match(value, "[^a-zA-Z0-9]"), "Punctuation or space", "Not Punctuation or space"</eval>
</change>
</input>
</fieldset>
<row>
<panel>
<table>
<search>
<query>| makeresults
| eval Text="$selText$ is $validationResult$"
| table Text</query>
<sampleRatio>1</sampleRatio>
</search>
<option name="count">20</option>
<option name="dataOverlayMode">none</option>
<option name="drilldown">cell</option>
<option name="percentagesRow">false</option>
<option name="rowNumbers">false</option>
<option name="totalsRow">false</option>
<option name="wrap">true</option>
</table>
</panel>
</row>
</form>
===============================================================
You could use a token modifier
| eval Text="$selText|s$ is $validationResult$"
You could include space as a valid character and then trim the value before using it
any suggestion about identifying " <double quotes> using regex ?
Which version of splunk are you using because I am not seeing that issue?
Version: 8.1.4 When I am inputting the string say, gfgfgf"hh.
It says 'Unbalanced Quotes' instead of the custom message from the else statement.