- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2022 02:40 AM
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);
Solved! Go to Solution.
- Labels:
-
Enterprise Asset Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2022 03:14 AM
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 :
Example 2 :
var regex = (/^(([0-9.]?)*)+$/);
var text="123.abc.345.435";
gs.print(regex.test(text));
Output :
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2022 04:31 AM
I am glad that your issue is resolved. Please mark appropriate answer as Correct so that others can get benefit from it in future.
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2022 01:28 AM
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.