Regex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2024 04:26 AM
Hi All,
I am using regex to get a alphanumeric value from a string . The regex i used is [A-Za-z0-9] . Please help me on this .
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2024 09:42 AM
Hi Kali,
The alphanumeric regex accepts if the string is having only alphabets/only numbers/both alphabets and numbers.
I hope there is no regex that returns true for alphanumeric and false for only alphabets and only numbers.
I have tried the below script in the background which returns the alphanumeric string:
Mark the response correct and helpful if the answer assisted your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2024 12:08 AM - edited 07-01-2024 12:22 AM
Hi @Rupanjani ,
var subject ="This is a sample case for 123AZBzxc";
var subjectarray = subject.split(' ');
gs.print(subjectarray);
var rg = new RegExp("^[a-zA-Z0-9]*$");
for(i=0;i>subjectarray.length;i++){
rg.match(subjectarray[i]);
}
gs.print(rg);
When i run this above in the background script i am getting the below as the return value.
/^[a-zA-Z0-9]*$/
@Steven Bell : Can you please check the code and let me know where the problem lies. I want to return a alphanumeric value .
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2024 01:45 AM
Hi kali,
Please try the exact code given in background script.
If you are using it in any other scripts, try yo use the if loop mentioned.
If loop gets satisfied, only if the string is alpha-numeric.
Mark the response correct and helpful if the answer assisted your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2024 05:09 AM
Hi @kali,
please check below link:
https://www.servicenow.com/community/developer-forum/validate-alpha-numeric/m-p/2179435
Thank you, please make helpful if you accept the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2024 06:50 AM
Hi @Yashsvi ,
I looked into docs , i am not getting the answer. Please look the script which i posted and let me know where the problem lies