Single line variable data restrictions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2024 01:58 PM
Hi,
I would like to write an accurate Catalog Client script that would give me the following results:
Variable 'xyz field name' should not accept any statement starting with ZX or ZK or XX or PK or PL etc. If user attempts to submit then it throws an error.
If the user does not initiate the statement then the field message must remain hidden.
Script should be on the lines below:
if (isLoading || newValue == '')
var pattern = [Zz][Xx], [Xx][Xx],[Pp][Hh],[Pp][Ll],[Pp][Kk],[Pp][Pp], [Pp][Tt], [Cc][Aa], [Zz][Kk], [Pp][Jj], [Ff][Ee], [Ff][Ff], [Ff][Ww], [Ff][Nn], [Pp][Mm], [Ll][Ll],
if(!pattern.test(newValue)){
g_form.showFieldMsg (‘xyz field name’, 'Please enter a valid id. For example, starting with either ‘SA’ or ‘XA’ or ‘xs’ or ‘XW’);
g_form.clearValue('xyz field name','');
return;
} else if pattern = [Ss][Aa], [Xx][Aa], [Xx][Ss], [Xx][Ww]; (SA or XA or XS or XW)
g_form.setValue(' xyz field,'');
g_form.HideFieldMsg(‘xyz field name’, 'Please enter a valid id. For example, starting with either ‘SA’ or ‘XA’ or ‘xs’ or ‘XW’);
}
}
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2024 02:46 PM
While I applaud your use of a regex, in this situation, I would use an object with properties:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2024 03:18 PM
RegExp
^(?!(?:ZX|ZK|XX|PK|PL|<add further not permitted initials here>)).*$
should do what you ask, but I would consider showing the error when the correct id is not entered.
I mean instead of checking for does not start with one of ZX, ZK, XX, PK or PL I'd check for starts with SA, XA, XS or XW.