SoFunction
Updated on 2025-04-10

B/s development commonly used javascript technology page 4/4


Verification of phone number

Require:
(1) Phone number consists of numbers, "(", ")" and "-"
(2) Phone numbers are 3 to 8 digits
(3) If the phone number contains an area code, then the area code is three or four digits
(4) Area codes are separated from other parts by "(", ")" or "-"
(5) The mobile phone number is 11 or 12 digits. If it is 12 digits, then the first digit is 0
(6) The first and second digits of the 11-digit mobile phone number are "13"
(7) The second and third digits of the 12-digit mobile phone number are "13"
According to these rules, the following regular expressions can be drawn:
(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)


<script language="java script">
function PhoneCheck(s) {
var str=s;
var reg=/(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/
alert((str));
}
</script>
<input type=text name="iphone">
<input type=button onclick="PhoneCheck()" value="Check">

It has the effect of not echoing non-numeric characters when inputting non-numeric characters, that is, it does not react to input of non-numeric characters.
function numbersonly(field,event){
 var key,keychar;
 if(){
  key = ;
 }
 else if (event){
  key = ;
 }
 else{
  return true
 }
 keychar = (key);
 if((key == null)||(key == 0)||(key == 8)||(key == 9)||(key == 13)||(key == 27)){
  return true;
 }
 else if(("0123456789.").indexOf(keychar)>-1){
   = "";
  return true;
 }
 else {
   = "Field excepts numbers only";
  return false;
 }
}

Verify ip

str=;
if(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.test(str)==false)
{
('Wrong IP address format');
 ();
 ();
 return;
}
if(RegExp.$1<1 || RegExp.$1>254||RegExp.$2<0||RegExp.$2>254||RegExp.$3<0||RegExp.$3>254||RegExp.$4<1||RegExp.$4>254)
{
('Wrong IP address');
 ();
 ();
 return;
}
//Exclude 0 like 010.020.020.03
var str=(/0(\d)/g,"$1");
str=(/0(\d)/g,"$1");
(str);


//The following is the class that fetches the data
//Obj parameter specifies the source of the data (qualified Table), the default first behavior field name line
//GetTableData class provides the MoveNext method, the parameters are the number of bits that move up or down in the table row, the positive number moves down, and the negative number goes up.
//GetFieldData method obtains the data of the specified column name
//Sort_desc method arranges the specified columns in descending order
//Sort_asc method arranges the specified columns in ascending order
//GetData method returns an array of data with a field value of a specific value, provides data, and other processing can be performed externally.
//Delete method deletes the current record, reduces the array by one line
//Initialization, Obj: the name of table, Leftlen: the excess data length on the left, Rightlen: the excess data length on the right,
function GetTableData(Obj,LeftLen,RightLen){
var MyObj=(Obj);
var iRow=;
var iLen=[0].;
var i,j;

TableData=new Array();
  for (i=0;i< iRow;i++){
   TableData[i]=new Array();
   for (j=0;j<iLen;j++){
   TableStr=(i).cells(j).innerText;
   TableStr=(LeftLen, -RightLen).Trim();
   TableStr=(/ /gi,"").replace(/\r\n/ig,"");
   TableData[i][j]=TableStr;
   }
   }

  =TableData; 
  =[0].length;
  =;
  =0;
}


function movenext(Step){
if (>=){
return
}

if (Step=="" || typeof(Step)=="undefined") {
 if (<-1)
 ++;
 return;

}
 else{
  if ( + Step<=-1 &&  + Step>=0 ){
  = + Step;
  }
  else
  {
  if ( + Step<0){
   = 0;
   return;
   }
  if ( + Step>-1){
   = -1;
   return;
   }
  }
 }
}


function getfielddata(Field){
var colindex=-1;
var i=0;
 if (typeof(Field) == "number"){
   colindex=Field;
  }
 else
 {
 for (i=0;i< && < ;i++){
   if ([0][i]==Field){
   colindex=i;
   break;
   }  
  }
 }
  if (colindex!=-1) {
  return [][colindex];
  }

}

 

function sort_desc(){// descending order
 var colindex=-1;
 var highindex=-1;
 desc_array=new Array();
 var i,j;
for (n=0; n<; n++){
 Field=arguments[-1-n];
 for (i=0;i<;i++){
  if ([0][i]==Field){
  colindex=i;
  break;
  }  
 }
   if ( colindex==-1 )
  return;
   else
  {
  desc_array[0]=[0];
  for(i=1;i<;i++){
  desc_array[i]=[1];
  highindex=1;
   for(j=1;j<;j++){
      if  (desc_array[i][colindex]<[j][colindex]){ 
      desc_array[i]=[j];   
      highindex=j;
    }

   }
     if (highindex!=-1)
     =(0,highindex).concat((highindex+1,));                      
  }
 }

 
 =desc_array;
}
 return;
}

 

function sort_asc(){//Asc
 var colindex=-1;
 var highindex=-1;
 var i,j;
for (n=0; n<; n++){
   asc_array=new Array();
   Field=arguments[-1-n];
   for (i=0;i<;i++){
    if ([0][i]==Field){
    colindex=i;
    break;
    }  
   }
   if ( colindex==-1 )
     return;
   else
     {
     asc_array[0]=[0];
     for(i=1;i<;i++){
     asc_array[i]=[1];
     highindex=1;
for(j=1;j<;j++){//Find out the smallest column value
         if  (asc_array[i][colindex]>[j][colindex]){ 
         asc_array[i]=[j];   
         highindex=j;

        }

       }
         if (highindex!=-1)
         =(0,highindex).concat((highindex+1,));                      

      }
     }

 
    =asc_array;
 }
 return;
}

 

function getData(Field,FieldValue){
var colindex=-1;
var i,j;

GetData=new Array();
  if (typeof(Field)=="undefined" || typeof(FieldValue)=="undefined" ){
  return ;
  }

   for(j=0;j<;j++){
      if  ([0][j]==Field){
     colindex=j;
     }
   }
   if (colindex!=-1){

   for(i=1;i<;i++){
      if  ([i][colindex]==FieldValue){
     GetData[i]=new Array();
     GetData[i]=[i]; 
     }
   }
   }
   return GetData;
}
function DeletE(){
=(0,).concat((+1,));                      
=;
return;
}
function updateField(Field,FieldValue){
var colindex=-1;
var i=0;
 if (typeof(Field) == "number"){
   colindex=Field;
  }
 else
 {
 for (i=0;i< && < ;i++){
   if ([0][i]==Field){
   colindex=i;
   break;
   }  
  }
 }
 if (colindex!=-1) {
  [][colindex]=FieldValue;
  }


}
function movefirst(){
=0;
}
function movelast(){
=-1;
}
function () {return (/(^\s*)|(\s*$)/g,"");}
 = movenext;
 = getfielddata;
.Sort_asc = sort_asc;
.Sort_desc = sort_desc;
 = getData;
 = DeletE;
 = updateField;
 = movefirst;

Specific example: http://202.119.73.208/NetEAn/com/test/

Call the verification code in the onblur event of each text box, and write an enter to tab function in the onKeyDown event in each text box.

//Replace the Enter key with tab
function enterToTab()
{
    if( != 'button' &&  != 'textarea'
       &&  == 13)
    {
         = 9;
    }
}

Sometimes you need to edit the form freely---
I'll give you a small example of freely editing the form. The writing is a bit messy, haha:)

//===============================start================================


<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=gb2312">
<TITLE>Test modification form</TITLE>
<STYLE>
/*Style of prompt layer*/
div
{
  BORDER-RIGHT: #80c144 1px solid;
  BORDER-TOP: #80c144 1px solid;
  VISIBILITY: hidden;
  BORDER-LEFT: #80c144 1px solid;
  CURSOR: default;
  LINE-HEIGHT: 20px;
  BORDER-BOTTOM: #80c144 1px solid;
FONT-FAMILY: Song font;
  font-size:12px;
  POSITION: absolute;
  BACKGROUND-COLOR: #f6f6f6;
  TOP:30px;
  LEFT:30px;
}
/*tr style*/
tr
{
font-family: "Zongyi";
    color: #000000;
    background-color: #C1DBF5;
    font-size: 12px
}
/*table footnote style*/
.TrFoot
{
    FONT-SIZE: 12px;
font-family:"An An", "Verdana", "Arial";
    BACKGROUND-COLOR: #6699CC;
    COLOR:#FFFFFF;
    height: 25;
}
/*trhead property*/
.TrHead
{
    FONT-SIZE: 13px;
font-family:"An An", "Verdana", "Arial";
    BACKGROUND-COLOR: #77AADD;
    COLOR:#FFFFFF;
    height: 25;
}
/*Text box style*/
INPUT
{
    BORDER-COLOR: #AACEF7 #AACEF7 #AACEF7 #AACEF7;
    BORDER-RIGHT: 1px solid;
    BORDER-TOP: 1px solid;
    BORDER-LEFT: 1px solid;
    BORDER-BOTTOM: 1px solid;
    FONT-SIZE: 12px;
FONT-FAMILY: “Zongyi”, “Verdana”;
    color: #000000;
    BACKGROUND-COLOR: #E9EFF5;
}
/*button style*/
button
{
    BORDER-COLOR: #AACEF7 #AACEF7 #AACEF7 #AACEF7;
    BACKGROUND-COLOR: #D5E4F3;
    CURSOR: hand;
    FONT-SIZE:12px;
    BORDER-RIGHT: 1px solid;
    BORDER-TOP: 1px solid;
    BORDER-LEFT: 1px solid;
    BORDER-BOTTOM: 1px solid;
    COLOR: #000000;
}
</STYLE>
</HEAD>
<BODY>
<SCRIPT language = "java script">
<!--Global Variable
//Flag bit, the value of false means that an edit box has not been opened, and the value of true means that an edit box has been opened to start editing.
var editer_table_cell_tag = false;
//Enable editing function flag, if the value is true, editing is allowed
var run_edit_flag = false;
//-->
</SCRIPT>

<SCRIPT language = "java script">
<!--
/**
* Edit table functions
* Click a cell to edit the contents inside freely
* @para tableID is the id of the table to be edited
* @para noEdiID The ID of the td that you do not edit, such as the title of the table
* Can be written as <TD >Free editing form</TD>
* This td cannot be edited at this time
 */
function editerTableCell(tableId,noEdiId)
{
 var tdObject = ;
 var tObject = (().parentNode).parentNode;
 if( == tableId && != noEdiId&&editer_table_cell_tag == false && run_edit_flag == true)
 {
= "<input type=text id=edit_table_txt name=edit_table_txt value="++" size='15' onKeyDown='enterToTab()'>  <input type=button value=' OKEY ' onclick='certainEdit()'>";
  edit_table_txt.focus();
  edit_table_txt.select();
  editer_table_cell_tag = true;
//Modify button prompt information
= "Please click the confirm button first to confirm the modification!";
 }
 else
 {
  return false;
 }
}

/**
* Confirm to modify
 */
function certainEdit()
{
 var bObject = ;
 var tdObject = ; 
 var txtObject = ;
  = ;
// means the editing box has been closed
 editer_table_cell_tag = false;
//Modify button prompt information
= "Please click a cell to edit!";
}

function enterToTab()
{
    if( != 'button' &&  != 'textarea'
       &&  == 13)
    {
         = 9;
    }
}

/**
* Control whether to edit
 */
function editStart()
{
if( == "Start editing")
 {
= "Edit completed";
  run_edit_flag = true;
 }
 else
 {
//If there is no edit box at present, the editing will be successful, otherwise, the submission cannot be submitted.
//You must press the OK button before you can submit it normally
  if(editer_table_cell_tag == false)
  {
alert("Editor ended successfully!");
= "Start editing";
   run_edit_flag = false;
  }
 }
}

/**
* Provide different prompt information according to different buttons
 */
function showTip()
{
if( == "Edit completed")
 {
   =  + 15;
   =  + 12;
   = "visible";  
 }
 else
 {
   = "hidden";   
 } 
}
-->
</SCRIPT>
<TABLE  width="100%" align="center" 
    onclick="editerTableCell('editer_table','no_editer')">  
    <TR class="TrHead">
<TD colspan="3" align="center" >Free editing forms</TD>
 </TR>
 <TR>
<TD width="33%">Click the Start Editing button, and then click each cell to edit</TD>
  <TD width="33%">2</TD>
  <TD width="33%">3</TD>
 </TR>
 <TR>
  <TD width="33%">4</TD>
  <TD width="33%">5</TD>
  <TD width="33%">6</TD>
 </TR>
 <TR>
  <TD width="33%">one</TD>
  <TD width="33%">two</TD>
  <TD width="33%">three</TD>
 </TR>
 <TR>
  <TD width="33%">four</TD>
  <TD width="33%">five</TD>
  <TD width="33%">six</TD>
 </TR>  
    <TR class="TrFoot">
  <TD colspan="3" align="center" >
<INPUT type="button" class="bt" value="Start editing" onClick="editStart()" onMouseOver="showTip()" onMouseMove="showTip()" onMouseOut=" = 'hidden';">
  </TD>
 </TR> 
</TABLE>
</BODY>
<DIV >Please click a cell to edit!</DIV>
</HTML> 
Previous page1234Read the full text