regex for an ip
Moderator: General Moderators
regex for an ip
Can anybody provide me with a regex that checks IP validity (I thought "[0-9]{1,3}/.[0-9]{1,3}/.[0-9]{1,3}/.[0-9]{1,3}) would work but it doesn't. I'm new at regex
This should be in the RegEx forum, as it is about... RegEx.
Code: Select all
preg_match("/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+(:[0-9]{1,5})?$/", $ipaddr);- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Jenk wrote:This should be in the RegEx forum, as it is about... RegEx.Code: Select all
preg_match("/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+(:[0-9]{1,5})?$/", $ipaddr);
Code: Select all
/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/