Regex Validation for IP address || CIDR || URL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2024 08:00 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2024 08:21 AM
Hi @Nandini DM,
Could you provide some examples of what you would like to see matched?
Your first regex isn't working for what I would expect it to validate.
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2024 08:33 AM
Hi @Peter Bodelier
First Regex will match for
1.1.1.1 --> Valid
11.11.11.11/32 --> Valid
11.22.33.44,11.22.33.44/12 --> Valid
Same way I want below to work
11.22.33.44,11.22.33.44/12,www.sample.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2024 08:58 AM - edited 07-11-2024 08:59 AM
Hi @Nandini DM ,
Can you please try the below regex.
new RegExp('^((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\\/([1-9]|[1-2][0-9]|3[0-2]))?|((www\\.)?((?:(?!www\\.|\\.).)+\\.[a-zA-Z0-9]+)))(\\s*,\\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\\/([1-9]|[1-2][0-9]|3[0-2]))?|((www\\.)?((?:(?!www\\.|\\.).)+\\.[a-zA-Z0-9]+))))*$', 'gm');
If my response has resolved your query, please consider giving it a thumbs up and marking it as the correct answer!
Thanks & Regards,
Sanjay Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2024 03:58 AM
Hi @Community Alums
In the below expression:
new RegExp('^((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\\/([1-9]|[1-2][0-9]|3[0-2]))?|((www\\.)?((?:(?!www\\.|\\.).)+\\.[a-zA-Z0-9]+)))(\\s*,\\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\\/([1-9]|[1-2][0-9]|3[0-2]))?|((www\\.)?((?:(?!www\\.|\\.).)+\\.[a-zA-Z0-9]+))))*$', 'gm');
How to make below URL to be Valid?
www.sample.com --> Valid
Sample.sample.com --> Valid (without www, it should allow 2 dots)
Sample.com -->Valid
How to change above expression to change URL only to make it possible