- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2022 03:03 AM
Hi All,
I have a requirement where field value should be restricted to 6 and out of which first two should be alphabet and last 4 to be numeric. In the alphabet part input can only be LP or DP.
eg. LP1000(any 4numeric value is ok) and DP8765
no restriction is there for numeric part, it can be any numeric value. Alphabet should be LP or DP. Can anyone help me for writing regex for this ?
Thanks in Advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2022 03:33 AM
Hi Priya,
If you are doing this on catalog item, Create a regex in variable validation regex table.
And use this logic:
^[LP|DP]{2}[0-9]{4}$
And in the variable attributes set this:
max_length=6 //so that user cannot enter more than 6 letters
(=tested)
Hope it helps.
Thanks,
Murthy
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2022 03:11 AM
Hi Priya,
You can go for the OnChange client script.
- Check the total length of the field is less than 6 if yes then alert & empty the field.
- If No, then concatenate the 1st & 2nd value & check if they are not DP or LP then alert & empty the field.
- If No, check the rest of the string is numeric if no then alerts & empty the field.
You can also use regex also & add the same in the field.
Regards,
Sunny Khandelwal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2022 03:13 AM
Hello
Please check this out:-
https://community.servicenow.com/community?id=community_article&sys_id=e334bc4cdbe0bf48fff8a345ca9619c5
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2022 03:33 AM
Hi Priya,
If you are doing this on catalog item, Create a regex in variable validation regex table.
And use this logic:
^[LP|DP]{2}[0-9]{4}$
And in the variable attributes set this:
max_length=6 //so that user cannot enter more than 6 letters
(=tested)
Hope it helps.
Thanks,
Murthy
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2022 04:42 AM
Thank you, it worked! 🙂