I'm writing an algorithm to validate an IPV4 address. An IPV4 is valid only if it has 4 octets separated by a "." and the numbers must be in the range (0-255) ONLY. eg 1.2.3.4 , 123.45.67.89 . I'm stuck trying the range part. I'm new to using regexp.
Asked
Active
Viewed 325 times
0
-
2Probable duplicate of https://stackoverflow.com/questions/4460586/javascript-regular-expression-to-check-for-ip-addresses . Regex is probably the wrong tool for the job. – Jeff Learman May 07 '18 at 16:24
-
4Possible duplicate of [javascript regular expression to check for IP addresses](https://stackoverflow.com/questions/4460586/javascript-regular-expression-to-check-for-ip-addresses) – May 07 '18 at 16:25
-
I'd agree-- rather than Regex, it would be way easier to [parse it to a number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt) then do range checks on that number. – Alexander Nied May 07 '18 at 16:26
-
1Welcome to StackOverflow. For the best experience here, be sure to try searching for your question before asking it. I found the above by googling `site:stackoverflow.com validate ip address javascript`. Of course, you can leave out the `site` part to get answers from anywhere. Also, please read [How to ask](https://stackoverflow.com/help/how-to-ask), and post a [Minimal, Complete, Verifiable Example](https://stackoverflow.com/help/mcve). If this were really a regex issue, we'd help you a lot better if you posted what you're trying. Show us your research, it helps! – Jeff Learman May 07 '18 at 16:27
-
You could use http://gamon.webfactional.com/regexnumericrangegenerator/ to generate numeric ranges for regexes – Cr4xy May 07 '18 at 17:03