Skip to content
Advertisement

Regular Expression | Leap Years and More

I’ve recently been looking for a regular expression to do some client side date checking, and I haven’t been able to find one that can satisfy the following criteria: Has a range from 1800 – Now Performs proper date checking with leap years MM/DD/YYYY Form Invalid Date Checking (These constraints were outside of my scope and are a requirement as

How to highlight text using javascript

Can someone help me with a javascript function that can highlight text on a web page. And the requirement is to – highlight only once, not like highlight all occurrences of the text as we do in case of search. Answer You can use the jquery highlight effect. But if you are interested in raw javascript code, take a look

Generic deep diff between two objects

I have two objects: oldObj and newObj. The data in oldObj was used to populate a form and newObj is the result of the user changing data in this form and submitting it. Both objects are deep, ie. they have properties that are objects or arrays of objects etc – they can be n levels deep, thus the diff algorithm

Javascript Named Function Expressions in Internet Explorer

Why does the following code not work in Internet Explorer (I’ve only tested in IE8 so far): If I change foo’s assignment to the following, the code works just fine: I imagine it’s something to do with named functions in IE’s Javascript engine. The code works fine in Chrome and Firefox. Any ideas? Answer IE has a lot of problems

How to start and stop/pause setInterval?

I’m trying to pause and then play a setInterval loop. After I have stopped the loop, the “start” button in my attempt doesn’t seem to work : Is there a working way to do this? Answer The reason you’re seeing this specific problem: JSFiddle wraps your code in a function, so start() is not defined in the global scope. Moral

Make a number a percentage

What’s the best way to strip the “0.”XXX% off a number and make it a percentage? What happens if the number happens to be an int? Answer A percentage is just: No need for anything fancy:

Advertisement