<html> <head> <title>test</title> <script type="text/javascript"> function checkIP(value){ var pattern = /^/d{1,3}(/./d{1,3}){3}$/; if (!pattern.exec(value)) { alert('please input valid ip address'); return false; } var ary = value.split('.'); for(key in ary) { if (parseInt(ary[key]) > 255){ alert('please input valid ip address'); return false; } } alert('valid ip address'); return true ; } </script> </head> <body> <input type="text" name="ip" οnchange="checkIP(this.value);"/> </body> </html> |
|