- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2022 10:09 PM
Hi All,
I need to validate a single line text field with only comma separated values.
Case 1 : With one input it should return true, example: Abel
Case 2 : With multiple input it should return true, example: Abel tuter, Sys Admin
Case 3: Any special characters except commas it should return false, example: Abel tuter,/Sys Admin (or) Abel tuter,%Sys Admin.
Do we have any regex for that. I have tried one or two it didn't worked.
Regards,
Sirraj
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2022 01:07 AM
Hi,
My code should work, I have tested in my PDI.
Anyway, you can add space in between '9' and ']' that will make it validate space as well. As below, I have made that part bold there is space.
var regex = (/^(([a-zA-Z0-9 ](,)?)*)+$/)
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-03-2022 01:06 AM
Hi Sirraj,
Try like this:
var regex = (/^(([a-zA-Z0-9\s](,)?)*)+$/);
var inputStr = "Abel ";
gs.print(regex.test(inputStr));
In addition, have a look at an Article I have written about Regular expression, that might give you some ideas as well:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2022 01:43 AM
Thank you Willem, its a nice article. One last query i need to allow white spaces between commas. But not after commas.
For ex - "Abel Tuter" should return true.
But "Abel Tuter, Sys Admin" should return false. After comma i dont need space. I saw your article, i guess i should do something with /S. But where exactly i need to paste this in my reg ex.