User input from HTML form fields is generally provided to JavaScript as a string. We’ve lived with that fact for decades but sometimes developers need to extract numbers from that string. There are multiple ways to get those numbers but let’s rely on regular expressions to extract those numbers!
To employ a regular expression to get a number within a string, we can use \d+
:
const string = "x12345david"; const [match] = string.match(/(\d+)/); match; // 12345
Regular expressions are capable of really powerful operations within JavaScript; this practice is one of the easier operations. Converting the number using a Number()
wrapper will give you the number as a Number
type.
LightFace: Facebook Lightbox for MooTools
One of the web components I’ve always loved has been Facebook’s modal dialog. This “lightbox” isn’t like others: no dark overlay, no obnoxious animating to size, and it doesn’t try to do “too much.” With Facebook’s dialog in mind, I’ve created LightFace: a Facebook lightbox…
Implement the Google AJAX Search API
Let’s be honest…WordPress’ search functionality isn’t great. Let’s be more honest…no search functionality is better than Google’s. Luckily for us, Google provides an awesome method by which we can use their search for our own site: the Google AJAX Search API.
Table Cell and Position Absolute
If you follow me on Twitter, you saw me rage about trying to make
position: absolute
work within aTD
element ordisplay: table-cell
element. Chrome? Check. Internet Explorer? Check. Firefox? Ugh, FML. I tinkered in the console…and cussed. I did some researched…and I…
Source link