Extract only numbers from a string in JavaScript

There are many ways to extract numbers from a string in JavaScript. Here’s the function we use: function ExtractOnlyNumbersFromString(txt) { var numbers = txt.match(/\d/g); return (numbers) ? numbers.join(“”) : “”; } ExtractOnlyNumbersFromString(“a 1 b 2…

Javascript | How to check sessionStorage support

var IS_SESSION_STORAGE_SUPPORTED; try { if (window.sessionStorage) { IS_SESSION_STORAGE_SUPPORTED = true; } else { IS_SESSION_STORAGE_SUPPORTED = false; } } catch (e) { IS_SESSION_STORAGE_SUPPORTED = false; } if (console) console.log(IS_SESSION_STORAGE_SUPPORTED);

Check if a string is an integer in javascript

Small function in pure Javascript to check if a string is an integer or not. function isInteger(value) { var intRegex = /^\d+$/; return intRegex.test(value); } isInteger(5); // true isInteger(undefined); // false isInteger(“1”); // true isInteger(“1.3”);…

Get query string parameters with jQuery

$.urlParam = function (name) { var results = new RegExp(‘[\?&]’ + name + ‘=([^&#]*)’) .exec(window.location.href); if (results == null) { return 0; } return results[1] || 0; } console.log($.urlParam(‘dotmaui’)); //cool

JavaScript loop through json array

If you are not interested in support for old browsers, the best way to browse an array of json is: var dotArrayJSON = [ {“label”: 1}, {“label”: 2}, {“label”: 3}, {“label”: 4} ]; dotArrayJSON.forEach(loopThrough); function…

Upload text file into textarea via Javascript

How to upload a text file in a textarea with Javascript. This script is used in dotmaui.com to upload files completely client-side, to respect the privacy of users. document.forms[‘myForm’].elements[‘myFile’].onchange = function (evt) { if (!window.FileReader)…