I have this pattern stored in a variable:
var regexServer = /^([0-9]{2,3})+\.([0-9]{2,3})+\.([0-9]{2,3})+\.([0-9]{2,3})+\:[0-9]{2,4}$/;
if(!stringFromArgument.match(regexServer))
alert("You must input a valid IP and a Port address! Eg: 66.77.88.99:8000");
I checked the string coming from the input (form), and it’s ok.
If somebody wants to add his own IP and Port address he must add a valid form. His string must contain only ., :, numbers and no whitespace.
What am I doing wrong?
First, no need put
(…)+if you just testing.Also you’ve limited 3rd and 4th numbers to 2+, but there could be numbers lower than 10 as well as the port could be greater than 9999.
Also, this regex only checks if correct format, but not validating the ip (checks if the numbers is between 0-255). Here is some more regex (without the port check, you can add it by your self):