Validation on accepting only numbers and dots in transform map for the field Name using regular expression.

Bhanupriya
Giga Contributor

Hi All,

   I need to validate the name field in transform map for incoming data through excel sheet (Data Load) using Regular expression.The condition is- the  name field should accept only numbers and dots in the following format. EX-1.0.001

I have tried the below Onbefore transform script but its ignoring all the records from the excel sheet though it is in correct format.please suggest the correct ANSWER.

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

var incomingName = source.u_name; // give the import set field name here

var regex = /^[0-9]*\.?[0-9]*$/;
var isValid = regex.test(incomingName);

if (!isValid) {

log.info('Invalid name');

ignore = true;

}
})(source, map, log, target);

 

1 ACCEPTED SOLUTION

Abhijit4
Mega Sage

Hi,

Your regex is not working properly. 

Try this regex pattern, it works fine.

var regex = (/^(([0-9.]?)*)+$/);

 

Tested example 1:

var regex = (/^(([0-9.]?)*)+$/);
var text="123.345.435";
gs.print(regex.test(text));

Output :

find_real_file.png

Example 2 : 

var regex = (/^(([0-9.]?)*)+$/);
var text="123.abc.345.435";
gs.print(regex.test(text));

Output :

find_real_file.png

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

View solution in original post

6 REPLIES 6

I am glad that your issue is resolved. Please mark appropriate answer as Correct so that others can get benefit from it in future.

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Hi Abhijit,

 

       What will be the regex when name field  should accepts only numbers and dots and also it should validate starting and end it should accept only numbers.I have tried this  from your answers but showing invalid regex. Please suggest.