- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 06:58 AM - edited 07-23-2024 07:00 AM
Hi,
I wrote a small script using regex for field validation which accepts only numbers and '-'. From my testing team, I got to know it is also accepting ',', '.'. Dot and Comma Kindly help
unction onChange (control, oldValue, newValue, isLoading){
if (isLoading | | newValue == ' ') {
return;
}
var re = /[0-9-]+/;
if (!re.test(newValue)){
g_form.addInfoMessage("vip_listener_port", "VIP Listener Port only accepts numbers and "-", 'error');
g_form.clearValue("vip_listener_port);
}
}
//I HAVE WRITTEN THIS CODE MANUALLY IN INSERT/CODE SAMPLE
Regards
Suman P.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 07:36 AM
Try this
^[0-9 \-]+$
Regards
Paul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 07:22 AM
Hi @Community Alums
^[0-9-]+$
Try with this in Background scripts test with possible Cases
function validateField(value) {
const pattern = /^[0-9-]+$/;
return pattern.test(value);
}
const testValues = ['123-456', '123,456', '123.456', '123456'];
testValues.forEach(function(value) {
g s .print(value + ": " + validateField(value));
});
Mark it Helpful and Accept Solution!! If this helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 07:36 AM
Try this
^[0-9 \-]+$
Regards
Paul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 07:58 AM
Since this is on a Catalog Item variable, you should be using Variable Validation Regex instead of a script.
^[0-9-]+
Works fine. Define it via the left nav menu, then select it on the Type Specification tab.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 07:36 PM