User should able to enter number and range should be 0 to 65536
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2024 04:54 AM
Hi Team,
We have one port number field and the user should only be able to enter 0 to 65536 and it should also accept (, and – Special characters)
For example : 22-23, 25, 80, 443, 2001-2020
Can someone please let me know how can I achieve this?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2024 05:27 AM
Hi @lucky24,
You may try with following onChange Client Script.
Please mark my response as correct and helpful if it helped solved your question.
Thanks,
Rohit Suryawanshi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2024 06:54 AM
If the field is on a table, you can use an onChange client script that contains a regex. If the field is on a catalog item, you can create a "Variable Validation Regex" and apply it to the field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2024 07:03 AM
Hello @lucky24 ,
To achieve this requirement, you can create on change client script on "port number" field and use regex for validation as below -
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var portField = g_form.getValue('number_field'); //replace the field name
// Regular expression to validate port numbers and ranges
var regex = /^\s*(6553[0-6]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[0-9]{1,4})(\s*-\s*(6553[0-6]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[0-9]{1,4}))?(\s*,\s*(6553[0-6]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[0-9]{1,4})(\s*-\s*(6553[0-6]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[0-9]{1,4}))?)*\s*$/;
// Validate the port number field against the regular expression
if (!regex.test(portField)) {
alert('Invalid port number format. Please enter values between 0 and 65536, using commas and hyphens as separators.');
}
}
I have tried it in my PDI and it worked for me.
If my answer solves your issue, please mark it as Accepted✔️ & Helpful👍!