How to allow number range in regex
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2024 10:15 PM
There is a field call Destination port which is a single line text field and a OnChange client script is written to allow number or number range (i.e 1119 or 1100-2000)
How to write regex for this??
var regEx = /^\d+$/;
if (!regEx.test(destination_port)) {
g_form.showFieldMsg("destination_port", "Please enter valid Destination Port number.", "error");
This is only allowing number i.e 110 but it should allow number range i.e 2000-3000.
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2024 08:31 AM - edited 01-02-2024 08:33 AM
Can you please try this regex
var num_ranger = /^(\d+(-\d+)?|\d+)$/;
if (!num_ranger.test(destination_port)) {
g_form.showFieldMsg("destination_port", "Please enter valid Destination Port number.", "error");
}
Please mark helpful, if this helped.
Thanks,