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.

priya130
Kilo Contributor

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

1 ACCEPTED SOLUTION

Murthy Ch
Giga Sage

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

Thanks,
Murthy

View solution in original post

5 REPLIES 5

Sunny Khandelwa
Kilo Guru

Hi Priya,

 

You can go for the OnChange client script.

  1. Check the total length of the field is less than 6 if yes then alert & empty the field.
  2. If No, then concatenate the 1st & 2nd value & check if they are not DP or LP then alert & empty the field.
  3. 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

 

Saurav11
Kilo Patron
Kilo Patron

Hello

Please check this out:-

https://community.servicenow.com/community?id=community_article&sys_id=e334bc4cdbe0bf48fff8a345ca9619c5

Thanks.

Murthy Ch
Giga Sage

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

Thanks,
Murthy

Thank you, it worked! 🙂