Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need a regular expression to verify that a string is an IP address. (It's not critical that it be a correct IP address; this is just a quick error check to make sure it's in that format.) This is what I have so far. Will it work all right?

^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$


The problem I can see is that it doesn't verify that each number is less than 256 (eg, you could enter 999.999.999.999), but I don't know how to combine regular expressions with mathematical ones, and I consider that more of a "room for improvement" situation than a critical problem.
Posted
Updated 10-Jun-13 9:58am
v2
Comments
CHill60 10-Jun-13 16:48pm    
Can't say for sure ... but have you come across this site for testing regex's and finding regex's regex tester[^]

1 solution

That looks like it should work. If you want something more accurate, you can check out this article[^].
 
Share this answer
 
Comments
CHill60 10-Jun-13 17:16pm    
my 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900