Ensuring numeric input to Salesforce

Posted by jack on September 3, 2016

A useful javascript snippet I used in a Cast Iron custom function to check any string is a number string. This is useful where the input is a string format user input that might includes invalid characters and the Salesforce entry is either a numeric field type or has validation that causes non-integer input to be rejected.  The function returns a zero if the input is not a valid integer string, to avoid errors inputting a null into a number field in salesforce – but in other circumstances it could return an empty string as indicated.

var returnValue;
var regex = new RegExp(‘^[0-9]$’);
if(regex.test(inputString)==true)returnValue=inputString;
else returnValue=’0′;  //alternatively  else returnValue =”;

return returnValue;

Categories: Cast Iron,Salesforce

Comments are closed.