Ruslan Ulanov’s Codeshack

The developer’s notebook

Archive for the ‘JavaScript’ Category

Factorial

leave a comment

A function that calculates a number’s factorial using recursion.

function factorial(n) {
    return n * ((n > 1) ? factorial(n - 1) : 1);
}

Written by Ruslan Ulanov

October 15th, 2013 at 1:02 am

Posted in JavaScript

Useful JavaScript Regular Expression Functions

leave a comment

Here’s a few links for commonly used REGEXs..

10+ Useful JavaScript Regular Expression Functions to improve your web applications efficiency

Check that an input string looks like a valid email address.

function isEmail (s) {
  var isEmail_re = /^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/;
  return String(s).search (isEmail_re) != -1;
}

Returns a string with everything but the digits removed. Could be used to validate phone numbers, etc.

function getDigits (s) {
  return s.replace (/[^\d]/g, “”);
}

Written by Ruslan Ulanov

September 4th, 2009 at 12:16 pm

Posted in JavaScript

Tagged with ,

Using Regular Expressions in YUI CellEditor

leave a comment

Here’s a nice example of validating data in DataTable’s CellEditor using regular expressions.

http://www.satyam.com.ar/yui/2.6.0/invoice.html

Written by Ruslan Ulanov

January 28th, 2009 at 2:35 pm

Posted in JavaScript

Tagged with ,

Mobile Web Best Practices 1.0

leave a comment

The World Wide Web Consortium (W3C) has recently published a document called Mobile Web Best Practices 1.0.

This document specifies Best Practices for delivering Web content to mobile devices. The principal objective is to improve the user experience of the Web when accessed from such devices.

It’s a good step toward making the Web accessible to millions of small screen devices, not blessed with a combination of iPhone’s hi-res LCD and a powerful Safari browser. 🙂

The document is available from W3C’s web site http://www.w3.org/TR/2008/REC-mobile-bp-20080729/

Written by Ruslan Ulanov

August 7th, 2008 at 2:30 pm

IRT.org Knowledge Base

leave a comment

IRT.org has a nice collection of FAQs on DHTML, JS, Java, CSS, etc.

http://www.irt.org/faq.htm

Written by Ruslan Ulanov

May 5th, 2008 at 7:07 pm

Javascript equivalent for PHP’s functions

leave a comment

Mr. Kevin van Zonneveld has a nice collection of PHP functions ported to JS.

For example sprintf:

Read the rest of this entry »

Written by Ruslan Ulanov

March 13th, 2008 at 8:23 pm

Posted in JavaScript

mredkj.com

leave a comment

A good JS and VB.NET resource with unpronounceable name at http://www.mredkj.com/index.html

Written by Ruslan Ulanov

March 13th, 2008 at 8:17 pm

Posted in JavaScript,VB.NET

Dynamically loading an external JavaScript or CSS file

leave a comment

To load a .js or .css file dynamically, in a nutshell, it means using DOM methods to first create a swanky new “SCRIPT” or “LINK” element, assign it the appropriate attributes, and finally, use element.appendChild() to add the element to the desired location within the document tree. It sounds a lot more fancy than it really is. Lets see how it all comes together:

 Read the rest of this entry »

Written by Ruslan Ulanov

March 6th, 2008 at 9:36 pm

Posted in JavaScript