- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2021 07:30 AM
Hi All.
I have one variable (Type - single line text) and I need Regex Pattern which allow only 4 digit (number) in this field
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2021 07:35 AM
To match exactly 4 digits:
/^\d{4}$/
^\d{4}$
Not more then 4:
/^\d{0,4}$/
^\d{0,4}$
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2021 07:35 AM
To match exactly 4 digits:
/^\d{4}$/
^\d{4}$
Not more then 4:
/^\d{0,4}$/
^\d{0,4}$

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2021 07:35 AM
Hi there,
For exactly 4 digits, this would work:
\d{4}$
or for up to 4:
\d{0,4}$
Since it's a variable, please don't go for client script. Use the variable validation regex option.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP
---
LinkedIn
Community article, blog, video list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2021 07:39 AM
For example:
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP
---
LinkedIn
Community article, blog, video list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2021 08:10 PM
Hi Radhe,
In regex pattern you can use both way to allow only 4 digit in the field.
To match four digit exactly
/^[0-9]{4}$/
OR
/^\d{4}$/
please mark helpful if you find it correct.
Thanks and Regards
Sushma Dhandge