Solved

In FSM Mobile validation for Alpha Numeric data in a field

  • 10 May 2024
  • 1 reply
  • 26 views

Badge +2

Hi All,

In FSM mobile can we check if in the field user is adding an alphanumeric value and trying to save to thrown an exception to add only numeric data. Is it possible using client script.

 

Thanks,

Lavanya

 

icon

Best answer by shalikakk 10 May 2024, 12:49

View original

1 reply

Userlevel 2
Badge +6

@B Lavanya You can use the following script to check whether the input values are numeric or not.

 

var inputValue = getControlValue("custom",”barcode”);
var vLength = getDBValues(stringFormat("SELECT LENGTH('{0}') AS len FROM task WHERE task_id = (SELECT MIN(task_id) FROM task)", inputValue));
var j = "";
var x = "";

for (var i = 1; i <= vLength[0]["len"]; i++)
{
    j = getDBValues(stringFormat("SELECT SUBSTRING('{0}', {1}, 1) AS char FROM task LIMIT 1", getFromCache("isNumeric"), i ));
    x = "a" + j[0]["char"];
if (x != "a0" && x != "a1" && x != "a2" && x != "a3" && x != "a4" &&
        x != "a5" && x != "a6" && x != "a7" && x != "a8" && x != "a9" && 
        x != "a." )
        {
return "0";
        }
}
return "1";


You can run the above script using the executeScript function. It returns 1 if the input is a numeric value. Otherwise it returns 0.

Thanks.

Reply