Verify IP address format and port number JS code

Source: Internet
Author: User

/*
Purpose: Verify the format of IP address
Input: Strip:ip Address
Returns: False if return true through validation;
*/
Java code

1. function f_check_ip (obj)
2. {
3. Var re=/^ (d+). (d+). (d+). (d+) $/; Regular expressions that match an IP address
4. if (Re.test (Obj.value))
5. {
6. If (regexp.$1 <256 && regexp.$2<256 && regexp.$3<256 && regexp.$4<256) Retu RN true;
7.}
8. F_alert (obj, "Please enter a legitimate computer IP address");
9. return false;
10.}
11.

function F_check_ip (obj)
{
var re=/^ (d+). (d+). (d+). (d+) $/; Regular expressions that match an IP address
if (Re.test (Obj.value))
{
if (regexp.$1 <256 && regexp.$2<256 && regexp.$3<256 && regexp.$4<256) return true;
}
F_alert (obj, "Please enter a legitimate computer IP address");
return false;
}


/*
Purpose: Check if the value of the input object conforms to the port number format
Input: str input string
Return: False if return true through validation
*/
Java code

   1. Function F_check_port (obj)  
   2. { 
   3.     if (!f_check_number (obj))  
   4.  & nbsp;      return false; 
   5.     if (obj.value < 65536)  
   6.         return true; 
 & nbsp 7.     F_alert (obj, "Enter the valid computer IP address port number"); 
   8.     Return false;  
   9.}  
  10.   

Function F_check_port (obj)
{
    if (!f_check_number (obj)
         return false;
    if (Obj.value < 65536)
        return true;
    F_alert (obj, "Please enter a legitimate computer IP address port number");
    return false;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.