Tech Sharing Blog

Web, Tech, Tips, Download Blog…

Advertisement

Posts Tagged ‘ Javascript ’

the following example use the javascript regular express to validate the value where Chinese charecter is not allow.


<script   language=javascript>   
    
  function   checkChinese(){   
    
      var   re   =   /[\u4E00-\u9FA0]+/;   
    
      if   (re.test(form1.tjiccode.value))   
    
      {   
    
          alert(“不允许输入中文!”);   
    
  return   false;   
    
      }   
    
  }   

Popularity: 1% [?]

Check the page’s last update date

  1. Go to any web site as you like
  2. Delete the content in the URL address bar
  3. Enter the following script javascript:alert(document.lastModified)
  4. Press Enter
  5. This code will display any web page’s last update including the specific time, so by using the this script, you will know that the content you get is that the latest or not
Tech share latest update is 11 Oct 2009 16:36:23

Tech share latest update is 11 Oct 2009 16:36:23

Popularity: 1% [?]

Most of the developer who working in MS platform will be used to the javascript window.attachEvent.


But maybe some of you don’t know that window.attachEvent is only working on IE7+ and Opera only. Your coding will hit an javascrpit error when running at IE 6 or any version of firefox.


To resolve this issue, you may need to modify your code as such:

Original Code:

window.attachEvent(“onload”, Page_load);

function Page_load(){
//function code
}


Modify code:

//set page event handlers
if (window.attachEvent) {

//IE and Opera
window.attachEvent(“onload”, Page_load);

} else if (window.addEventListener) {

// IE 6
window.addEventListener(“load”, Page_Unload, false);

} else {

//FireFox
document.addEventListener(“load”, Page_Unload, false);

}

function Page_load(){

//function code

}


Popularity: 1% [?]

There is always the good way to prevent and verify the using enter data, especially for each text box or text area.


The following is script use the event object to check on the key code that the user enter, return false to prevent user to enter.


Disabled space to be enter in javascript

onKeypress=”if (event.keyCode == 32) event.returnValue = false;”


Sample:


Only allow number and . to be enter in javascript

onkeypress=”if (event.keyCode < 47 || event.keyCode /> 57) event.returnValue = false;”


Sample:

Popularity: 1% [?]

Trim a string in Javascript

By David on June 13, 2009


Trim is a good features when you try to delete the space at the left most, right most or both the left most and right most of the string. The following trim function is ultilize the javascript Regular expression for the trim function


Left Trim

function ltrim(str){

    return str.replace(/^\s+/, ”);

}


Right Trim

function rtrim(str) {

    return str.replace(/\s+$/, ”);

}


All trim

function alltrim(str) {

    return str.replace(/^\s+|\s+$/g, ”);

}


Popularity: 1% [?]

SEO Powered by Platinum SEO from Techblissonline