Php uses the preg_match () function to verify the IP address.
This example describes how php uses the preg_match () function to verify IP addresses. We will share this with you for your reference. The details are as follows:
<? Php/** @ return Boolen * @ param String $ ip address to be matched * @ param String $ regular rule matching pat * @ param Boolen Boolean value returned after successful match * preg_match () * 0 is unsuccessful, 1 is successful */function fun ($ ip) {// 0.0.0.0 --- 255.255.255.255 $ pat = "/^ (1? \ D {1, 2}) | (2 [0-4] \ d) | (25 [0-5]) \.) {3} (1? \ D {1, 2}) | (2 [0-4] \ d) | (25 [0-5]) $/"; if (preg_match ($ pat, $ ip) {$ num = preg_match ($ pat, $ ip); return $ num;} else {$ num = preg_match ($ pat, $ ip ); return $ num ;}} echo fun ("00000000255 ");
PS: here we will provide two very convenient Regular Expression tools for your reference:
JavaScript Regular Expression online testing tool:
Http://tools.jb51.net/regex/javascript
Regular Expression generation tool:
Http://tools.jb51.net/regex/create_reg