Archive for the 'Client' Category

 

node.js learning with learnyounode .. solutions ..

May 08, 2015 in javascript, node.js

Exercise 4, asynchronous (async) file processing ..

From: https://github.com/JeffPaine/learnyounode-solutions

[js]

var countLines = function (err, fileBuffer){
// console.log(fileBuffer);
console.log(fileBuffer.split(‘\n’).length);
};

fs.readFile(process.argv[2], ‘utf8’, countLines);

[/js]

Javascript regular expressions (regex, regexp) .. city, state, zip (postal code) ..

Dec 14, 2011 in javascript, Web

Check for zip / postal code :

  if (field.value.search(/^\d{5}$/) != -1) {
    ...
  }

Check for “city, state zip” (space zip..) :

(note the 5\4 zip check.. like anybody would enter a 9 digit zip.. right..)

  if (field.value.search(/([^,]+),\s*(\w{2})\s*(\d{5}(?:-\d{4})?)/) != -1 ) {
    ...
  }

Check for “city, state” :

  if (field.value.search(/([^,]+),\s*(\w{2})/) != -1 ) {
    ...
  }

Href for JavaScript links: “#” or “javascript:void(0)”?

Nov 06, 2011 in javascript

From: http://stackoverflow.com/questions/134845/href-for-javascript-links-or-javascriptvoid0

When building a link that has the sole purpose to run JavaScript code, is it better to

<a href="#" onclick="myJsFunc();">Link</a>

or

<a href="javascript:void(0)" onclick="myJsFunc();">Link</a>

?