An example of IP address verification

Source: Internet
Author: User
Tags eval
I usually feel that the Windows IP input box is very easy to use. It must be nice if it can be implemented on a webpage. The core code is as follows:
<Script language = "javascript">
Function outStr (){
If (document. all. ip1.value> 0 & document. all. ip2.value> 0 & document. all. ip3.value> 0 & document. all. ip4.value> 0 ){
Alert ("The IP address you entered is:" + document. all. ip1.value + ". "+ document. all. ip2.value + ". "+ document. all. ip3.value + ". "+ document. all. ip4.value );
} // End if
} // End
Function moveRight (obj ){
Id = parseInt (obj. name. substr (2, 1 ))
If (id <4 ){
Eval ("document. all. ip" + (id + 1) + ". focus ()");
} Else {
OutStr ();
} // End if
}
Function moveLeft (obj ){
Id = parseInt (obj. name. substr (2, 1 ))
If (id> 1 ){
Eval ("document. all. ip" + (id-1) + ". focus ()");
} // End if
} // End if
Function Keypress (obj ){
Var objInput = obj;
Cod = window. event. keyCode;

If (cod = 46 & (obj. value). length> 0) {// if you press "." and have a character, move it to the right once.
Window. event. keyCode = 0;
MoveRight (obj );
} Else if (obj. value). length = 2 & (cod> = 48) & (cod <= 57) {// if the number key has two digits
If (cod <58 ){//
Obj. value = obj. value * 10 + cod-48;
} // End if
Window. event. keyCode = 0;
MoveRight (obj );
} Else {// determines if the input is a number.
If (! (Cod> = 48) & (cod <= 57) | (cod = 13) | (cod = 37) | (cod = 39 ))){
Window. event. keyCode = 0;
} // End if
} // End if
} // End function keydown
Function getCaretPos (obj ){
Var currentRange = document. selection. createRange ();
Var workRange = currentRange. duplicate ();
Obj. select ();
Var allRange = document. selection. createRange ();
Var len = 0;
While (workRange. compareEndPoints ("StartToStart", allRange)> 0 ){

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.