- 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 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 03:30 AM
Hi Abhjit
The one you posted regular expression its working fine but i need the regular expression in the following format. Ex-2.0.001(first number then dot again single number and then dot followed by 3 numbers )
Dot should not be accepted at starting and end or it always starts and ends with numbers.Please suggest.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2022 03:43 AM
Hi,
I have created below regex pattern for your requirement and tested the same.
(/^([0-9]{1}.[0-9]{1}.[0-9]{3})+$/);
This will allow only formats as you mentioned 2.0.001, if you think number length can vary at first place e.g. 222.0.001 then you can add highest length parameter as well like below,
(/^([0-9]{1,3}.[0-9]{1}.[0-9]{3})+$/);
Same goes for digits after second, you can configure digit length as per your need.
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:04 AM
Hi Abhijit,
The above regex is working fine .Thank you so much for the explanation.